*****************************************************************************************************************************************************
* PROJECT: 		WEALTH LOSSES DUE TO CORONA PANDEMIC
* DATE: 		2020-November
* CONTENT: 		Generate baseline data file
* AUTHORS: 		Johannes Wohlfart, Tobin Hanspal, Anni Weber
*****************************************************************************************************************************************************

		clear all
		set scheme lean2
		global pm = char(177)
		set more off
		gl date = c(current_date)
		graph set window fontface "cmr10"
		set graphics on  
		set type double 
		
		
		
* set cd as /Replication_files_HanspalWeberWohlfart2020/
cd "C:\Users\User\Dropbox\RESEARCH\000 Projects\007 Corona wealth losses US\Post acceptance\Replication_files_HanspalWeberWohlfart2020"
		
		
import delimited "data/raw/raw.csv", varnames(1) 

count 

** 0) ATTENTION SCREENER 
********************************************
keep if attention=="1"

drop q181_1- q181_5

destring gender age state education hh_income employment_situation retirementwealthjan otherfinwealthjan riskyshareretirejan ///
riskyshareotherjan lossretir loss_ret_perc lossretirrout2 gain_ret_per q133 finloss q135 fingain joblossq1 incloss1 incgain ///
incloss prior prior_dotcom prior_blackmonday posterior manip1 manip2 manip3 manip_ownwealth manip_ownwealth_7_text ///
stockret_distr_1 stockret_distr_2 stockret_distr_3 stockret_distr_4 stockret_distr_5 stockret_distr_6 stockret_distr_7 ///
stockret_distr_8 prospecthh q146 spendhigher spendlower netincrout incgain2020 incloss2020 owninc_year owninc_year_7_text expec_retireage ///
expec_desiredhours debt traderealized tradeplanned creditconstr fincrisis_loss dotcom_loss blackmonday_loss fin_knowledge_1 ///
stockexperience risk_tolerance_1 hhdecision_1 laborincome industry_1 industry_2 mainearner hhsize zipcode marital ///
pol birthyear realestatejan debtjan netincome google attention treatment, replace

drop status ipaddress progress


drop if google==. // drop incompletes

** 1) SURVEY ADMIN VARIABLES 
********************************************

order responseid, first 
format responseid %17s

order rid treatment attention, after(responseid)
label variable rid "ResponseId2"	
drop if rid==""

destring finished, replace

drop recipientlastname- recipientemail externalreference distributionchannel userlanguage
drop q188- q164_resolution 

destring locationlatitude , replace
destring locationlongitude, replace

*~ treatment arm 
label define treatment ///
0 "ctrl pure" ///
1 "ctrl fincris" ///
2 "tr fincris" ///
3 "ctrl dotcom" ///
4 "tr dotcom" ///
5 "ctrl blackmon" ///
6 "tr blackmon"

label values treatment treatment
label variable treatment "treatment arm"

gen control_pure=(treatment==0) if treatment!=.
gen control_fincrisis=(treatment==1) if treatment!=.
gen tr_fincrisis=(treatment==2) if treatment!=.
gen control_dotcom=(treatment==3) if treatment!=.
gen tr_dotcom=(treatment==4) if treatment!=.
gen control_black=(treatment==5) if treatment!=.
gen tr_black=(treatment==6) if treatment!=.

order control_pure-tr_black, after(treatment)


*~ survey date 
gen x=substr(startdate,1,10)
order x, after(startdate)
gen svydate=date(x, "YMD")
order svydate, after(x)
format svydate %td
drop startdate enddate x recordeddate


*~ response time 
destring durationinseconds,  replace
gen svytime_min=durationin/60
order svytime, after(duration)
drop durationinsec 
label variable svytime_min "response time in minutes"



** 2) DEMOGRAPHICS FOR QUOTAS 
********************************************

		*~ gender
		tab gender
			label variable gender "respondent gender"
		label define gender 1 "male" 2 "female"
		label values gender gender

		gen female=(gender==2 & gender!=.)
			label variable female "female"
		gen male=(gender==1 & gender!=.)
			label variable male "male"
		order female male, after(gender)
			
		*~age category
		tab age
		rename age agecat
		label variable agecat "respondent age category"
		label define agecat 1 "18-24 years" 2 "25-34 years" 3 "35-44 years" ///
							4 "45-54 years" 5 "55-64 years" 6 "65 years and older"
		label values agecat agecat

		gen age_18_24=(agecat==1) if agecat!=.
		la var age_18_24 "Age 18-24"
		gen age_25_34=(agecat==2) if agecat!=.
		la var age_25_34 "Age 25-34"
		gen age_35_44=(agecat==3) if agecat!=.
		la var age_35_44 "Age 35-44"
		gen age_45_54=(agecat==4) if agecat!=.
		la var age_45_54 "Age 45-54"
		gen age_55_64=(agecat==5) if agecat!=.
		la var age_55_64 "Age 55-64"
		gen age_65=(agecat==6) if agecat!=.
		la var age_65 "Age 65 and older"
		order age_18_24- age_65, after(agecat)

		gen age_check=age_18_24+age_25_34+age_35_44+age_45_54+age_55_64+age_65
		tab age_check, m
		drop age_check


		*~state of residence 

		label define state ///
		1	"AL" 2	"AK" 3	"AZ" 4	"AR" 5	"CA" 6 "CO" 7 "CT" ///
		8	"DE" 9	"DC" 10 "FL" 11 "GA" 12	"HI" 13	"ID" 14	"IL" 15	"IN" ///
		16	"IA" 17	"KS"  18 "KY" 19 "LA" 20 "ME" 21 "MD" 22 "MA" 23 "MI" ///
		24	"MN" 25	"MS" 26	"MO" 27	"MT" 28	"NE" 29 "NV" 30 "NH" 31	"NJ" ///
		32	"NM" 33	"NY" 34	"NC" 35	"ND" 36	"OH" 37	"OK" 38	"OR" 39	"PA" ///
		40  "PR" 41	"RI" 42	"SC" 43	"SD" 44	"TN" 45	"TX" 46	"UT" 47	"VT" ///
		48	"VA" 49	"WA" 50	"WV" 51	"WI" 52	"WY" 53	"outside US"

		label values state state
		label variable state "respondent state of residence"
		tab state, sort

		drop if state== 53 // drop respondents residing outside the US 

		gen region=.
		label define region ///
		1 "Region West" 2 "Region Midwest" 3 "Region Northeast" 4 "Region South"
		label values region region 
		replace region=1 if state==3 	| state==6 |state==13 |state==27 | state==29 |state==32 /// 
										| state==46 |state==52 |state==2 | state==5 |state==12 |state==38 |state==49
		replace region=2 if state==14 	| state==15 |state==23 |state==36 |state==51 |state==16 |state==17 | ///
										  state==24 |state==26 |state==28 |state==35 |state==43
		replace region=3 if state==7  	| state==20 | state==22 | state==30 | state==41 | state==47 | state==31 ///
										| state==33 | state==39
		replace region=4 if state==8 	| state==10 | state==11 | state==21 | state==34 | state==42 | state==9 ///
										| state==48 | state==50 | state==1 | state==18 | state==25 | state==44 ///
										| state==4 | state==19 | state==37 | state==45

		label variable region "respondent census region"
									
		gen west=(region==1) if region!=.
		la var west "Region West"
		gen midwest=(region==2) if region!=.
		la var midwest "Region Midwest"
		gen northeast=(region==3) if region!=.
		la var northeast "Region Northeast"
		gen south=(region==4) if region!=.
		la var south "Region South"

		gen region_check=northeast+midwest+south+west
		tab region_check, m // missing for those outside US
		drop region_check

		order region-south, after(state)

		*~ education 

		label variable education "respondent highest level of education completed"
		label define education ///
		1 "Below highschool" 2 "Highschool" 3 "Some college" 4 "Associate degree" ///
		5 "Bachelor's degree" 6 "Post-graduate degree"
		label values education education 

		gen below_highschool=(educ==1) if educ!=.
		la var below_highschool "Below highschool"
		gen highschool=(educ==2) if educ!=.
		la var highschool "Highschool"
		gen some_college=(educ==3) if educ!=.
		la var some_college "Some college"
		gen associate_degree=(educ==4) if educ!=.
		la var associate_degree "Associate degree"
		gen bachelors_degree=(educ==5) if educ!=.
		la var bachelors_degree "Bachelor's degree"
		gen postgrad_degree=(educ==6) if educ!=.
		la var postgrad_degree "Post-graduate degree"

		gen educ_check=below_highschool+highschool+some_college+associate_degree+bachelors_degree+postgrad_degree
		tab educ_check, m
		drop educ_check

		gen atleast_bachelor=(educ>=5) if educ!=.
		la var atleast_bachelor "At least bachelor's degree"
		gen below_bachelor=1-atleast_bachelor
		replace below_bachelor=. if education==.
		la var below_bachelor "Below bachelor's degree"
		order below_highschool-below_bachelor, after(education)

		*~ total gross income 

		label variable hh_income "total gross income of the respondent's household"
		label define hh_income ///
		1 "Gross Income < $15,000" 2 "$15,000 < Gross Income < $25,000" ///
		3 "$25,000 < Gross Income < $50,000" 4 "$50,000 < Gross Income < $75,000" ///
		5 "$75,000 < Gross Income < $100,000" 6 "$100,000 < Gross Income < $150,000" ///
		7 "$150,000 < Gross Income < $200,000" 8 "Gross Income > $200,000" ///
		9 "Gross Income: Prefer not to say"
		label values hh_income hh_income

		gen inc_15000=(hh_income==1) if hh_income!=.
		la var inc_15000 "Income < 15,000"
		gen inc_15000_25000=(hh_income==2) if hh_income!=.
		la var inc_15000_25000 "15,000 < Income < 25,000"
		gen inc_25000_50000=(hh_income==3) if hh_income!=.
		la var inc_25000_50000 "25,000 < Income < 50,000"
		gen inc_50000_75000=(hh_income==4) if hh_income!=.
		la var inc_50000_75000 "50,000 < Income < 75,000"
		gen inc_75000_100000=(hh_income==5) if hh_income!=.
		la var inc_75000_100000 "75,000 < Income < 100,000"
		gen inc_100000_150000=(hh_income==6) if hh_income!=.
		la var inc_100000_150000 "100,000 < Income < 150,000"
		gen inc_150000_200000=(hh_income==7) if hh_income!=.
		la var inc_150000_200000 "150,000 < Income < 200,000"
		gen inc_200000=(hh_income==8) if hh_income!=.
		la var inc_200000 "Income > 200,000"
		gen inc_NR=(hh_income==9)
		la var inc_NR "Income: Prefer not to say"

		gen income_check=inc_15000+inc_15000_25000+inc_25000_50000+inc_50000_75000+inc_75000_100000+inc_100000_150000+inc_150000_200000+inc_200000+inc_NR
		tab income_check, m
		drop income_check
		order inc_15000-inc_NR, after(hh_income)
		/*gen log_income=log(income)
		la var log_income "Log(Income)"
		*/

		*~ employment status 

		tab employment_situation
		label variable employment_situation "respondent employment status as of Jan 2020"
		label define employment ///
		1 "Full-time employed" 2 "Part-time employed" 9 "Self-employed" 3 "Unemployed" ///
		5 "Retired" 7 "Student" 10 "Homemaker" 6  "Other employment status"
		label values employment_situation employment 

		gen empl_ft=(employment_situation==1) if employment_situation!=.
		la var empl_ft "Full-time employed"
		gen empl_pt=(employment_situation==2) if employment_situation!=.
		la var empl_pt "Part-time employed"
		gen self_empl=(employment_situation==9) if employment_situation!=.
		la var self_empl "Self-employed"
		gen unempl=(employment_situation==3) if employment_situation!=.
		la var unempl "Unemployed"
		gen retired=(employment_situation==5) if employment_situation!=.
		la var retired "Retired"
		gen student=(employment_situation==7) if employment_situation!=.
		la var student "Student"
		gen empl_other=(employment_situation==6) if employment_situation!=.
		la var empl_other "Other employment status"
		gen empl_home=(employment_situation==10) if employment_situation!=.
		la var empl_home "Homemaker"

		gen empl_check=empl_ft+empl_pt+self_empl+unempl+empl_home+retired+student+empl_other
		tab empl_check, m
		drop empl_check

		gen employed=empl_pt+empl_ft if employment_situation!=.
		la var employed "indicator =1 if respondent is employed"
		order empl_ft- employed, after(employment_situation)

		rename employment_situation_6_text employment_sit_io
		label variable employment_sit_io "Employment status: text entry if OTHER is selected"
		order employment_sit_io, after(employment_situation)

		
		

************************
************************
************************



** 3) ASSETS AND DEBT AS OF JANUARY 2019
********************************************


			* 3.1) RETIREMENT WEALTH JANUARY 2020
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
			/*Please think of all your householdӳ retirement accounts, including 401(K)s,
			IRAs, or Keogh accounts.

			About how much were your household's investments in these accounts worth at
			the end of January 2020, i.e. before the start of the current crisis?

			If your household did not have any retirement accounts, please select $0. */ 

				
			rename retirementwealthjan retirwealth_Jan20
			replace retirwealth_Jan20=retirwealth_Jan20-2
			label define retirwealth_Jan20 ///
			1 "$0" 						2 "$1 - $999" 	///
			3 "$1,000 - $4,999" 		4 "$5,000 - $9,999" ///
			5 "$10,000 - $24,999" 		6 "$25,000 - $49,999"	///	
			7 "$50,000 - $74,999" 		8 "$75,000 - $99,999" ///
			9 "$100,000- $124,999" 		10 "$125,000- $149,999" ///
			11 "$150,000- $174,999" 	12 "$175,000- $199,999" ///
			13 "$200,000 - $249.999" 	14 "$250,000 - $499,000" ///
			15 "$500,000 and more" 		16 "Prefer not to say."

			label values retirwealth_Jan20 retirwealth_Jan20
			label variable retirwealth_Jan20 "total value hh retirement accounts as of January 2020"

			tab retirwealth_Jan20, gen(retirJan20_)
			order retirJan20_1- retirJan20_16, after(retirwealth_Jan20)

					rename retirJan20_1 retirJan20_0
					rename retirJan20_2 retirJan20_1k
					rename retirJan20_3 retirJan20_1k_5k
					rename retirJan20_4 retirJan20_5k_10k
					rename retirJan20_5 retirJan20_10k_25k
					rename retirJan20_6 retirJan20_25k_50k
					rename retirJan20_7 retirJan20_50k_75k
					rename retirJan20_8 retirJan20_75k_100k
					rename retirJan20_9 retirJan20_100k_125k
					rename retirJan20_10 retirJan20_125k_150k
					rename retirJan20_11 retirJan20_150k_175k
					rename retirJan20_12 retirJan20_175k_200k
					rename retirJan20_13 retirJan20_200k_250k
					rename retirJan20_14 retirJan20_250k_500k
					rename retirJan20_15 retirJan20_500k
					rename retirJan20_16 retirJan20_NR


					
					
			* 3.2) OTHER FINANCIAL ASSETS JANUARY 2020 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
			/*Please think of all your householdӳ other investable financial assets (outside
			of retirement accounts).

			What was the total value of these assets at the end of January 2020, i.e.
			before the start of the current crisis?
			Please include the value of all your householdӳ bank accounts, brokerage
			accounts, etc. Please do NOT include the value of any real estate property or
			any private business you own. Please do also NOT include the value of your
			retirement accounts you already reported above.

			If your household did not have any other investable financial assets, please
			select $0.
			*/

			rename otherfinwealthjan ofinwealth_Jan20
			replace ofinwealth_Jan20=1 if ofinwealth_Jan20==7
			replace ofinwealth_Jan20=2 if ofinwealth_Jan20==8
			replace ofinwealth_Jan20=3 if ofinwealth_Jan20==10
			replace ofinwealth_Jan20=4 if ofinwealth_Jan20==11
			replace ofinwealth_Jan20=5 if ofinwealth_Jan20==12
			replace ofinwealth_Jan20=6 if ofinwealth_Jan20==13
			replace ofinwealth_Jan20=7 if ofinwealth_Jan20==14
			replace ofinwealth_Jan20=8 if ofinwealth_Jan20==15
			replace ofinwealth_Jan20=9 if ofinwealth_Jan20==16
			replace ofinwealth_Jan20=10 if ofinwealth_Jan20==17
			replace ofinwealth_Jan20=11 if ofinwealth_Jan20==18
			replace ofinwealth_Jan20=12 if ofinwealth_Jan20==19
			replace ofinwealth_Jan20=13 if ofinwealth_Jan20==20
			replace ofinwealth_Jan20=14 if ofinwealth_Jan20==21
			replace ofinwealth_Jan20=15 if ofinwealth_Jan20==22
			replace ofinwealth_Jan20=16 if ofinwealth_Jan20==23

			label define ofinwealth_Jan20 ///
			1 "$0" 						2 "$1 - $999" 	///
			3 "$1,000 - $4,999" 		4 "$5,000 - $9,999" ///
			5 "$10,000 - $24,999" 		6 "$25,000 - $49,999"	///	
			7 "$50,000 - $74,999" 		8 "$75,000 - $99,999" ///
			9 "$100,000- $124,999" 		10 "$125,000- $149,999" ///
			11 "$150,000- $174,999" 	12 "$175,000- $199,999" ///
			13 "$200,000 - $249.999" 	14 "$250,000 - $499,000" ///
			15 "$500,000 and more" 		16 "Prefer not to say."
			label values ofinwealth_Jan20 ofinwealth_Jan20

			label variable ofinwealth_Jan20 "total value hh other financial assets (ex retir accounts) as of January 2020"


			tab ofinwealth_Jan20, gen(ofinJan20_)
			order ofinJan20_1- ofinJan20_16, after(ofinwealth_Jan20)
			
			rename ofinJan20_1 ofinJan20_0
			rename ofinJan20_2 ofinJan20_1k
			rename ofinJan20_3 ofinJan20_1k_5k
			rename ofinJan20_4 ofinJan20_5k_10k
			rename ofinJan20_5 ofinJan20_10k_25k
			rename ofinJan20_6 ofinJan20_25k_50k
			rename ofinJan20_7 ofinJan20_50k_75k
			rename ofinJan20_8 ofinJan20_75k_100k
			rename ofinJan20_9 ofinJan20_100k_125k
			rename ofinJan20_10 ofinJan20_125k_150k
			rename ofinJan20_11 ofinJan20_150k_175k
			rename ofinJan20_12 ofinJan20_175k_200k
			rename ofinJan20_13 ofinJan20_200k_250k
			rename ofinJan20_14 ofinJan20_250k_500k
			rename ofinJan20_15 ofinJan20_500k
			rename ofinJan20_16 ofinJan20_NR
			

			
			
						
			* 3.3) STOCK SHARES
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
			
			/*About what percent of the investments in your householdӳ retirement accounts
			was in stocks or stock mutual funds at the end of January 2020?*/

				rename riskyshareretirejan riskshare_retirwealth_Jan20 
				replace riskshare_retirwealth=. if retirwealth_Jan20==1
				label variable riskshare_retirwealth "share of retirement wealth invested in equity as of Jan 2020"

			/*And about what percent of your householdӳ other investments in financial
			assets (outside of retirement accounts) was in stocks or stock mutual funds at
			the end of January 2020?
			*/
				rename riskyshareotherjan  riskshare_ofinwealth_Jan20
				replace riskshare_ofinwealth=. if ofinwealth_Jan20==.
				replace riskshare_ofinwealth=. if ofinwealth_Jan20==1
				label variable riskshare_ofinwealth "share of other financial wealth invested in equity as of Jan 2020"
				
				
				
				* STOCK SHARE IN TOT FINANCIAL WEALTH 
				*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				
				*= weighted average stock share in retirement wealth and other financial wealth 
				

				sum riskshare_retirwealth if retirwealth_Jan20<16 & retirwealth_Jan20!=. //1,667
				sum riskshare_ofinwealth if ofinwealth_Jan20<16 & ofinwealth_Jan20!=. //1,811
				count if retirwealth_Jan20<16 & retirwealth_Jan20>1 & retirwealth_Jan20!=. //1,667
				count if ofinwealth_Jan20<16 & ofinwealth_Jan20>1 & ofinwealth_Jan20!=. //1,811
				count if ofinwealth_Jan20<16 & ofinwealth_Jan20>1 & ofinwealth_Jan20!=. | ///
				retirwealth_Jan20<16 & retirwealth_Jan20>1 & retirwealth_Jan20!=. //2,031
				
				gen ofinJan20_midpt=. 
				replace ofinJan20_midpt=0 if ofinwealth_Jan20==1
				replace ofinJan20_midpt=500 if ofinwealth_Jan20==2
				replace ofinJan20_midpt=2500 if ofinwealth_Jan20==3
				replace ofinJan20_midpt=7500 if ofinwealth_Jan20==4
				replace ofinJan20_midpt=17500 if ofinwealth_Jan20==5
				replace ofinJan20_midpt=37500 if ofinwealth_Jan20==6
				replace ofinJan20_midpt=62500 if ofinwealth_Jan20==7
				replace ofinJan20_midpt=87500 if ofinwealth_Jan20==8
				replace ofinJan20_midpt=112500 if ofinwealth_Jan20==9
				replace ofinJan20_midpt=137500 if ofinwealth_Jan20==10
				replace ofinJan20_midpt=162500 if ofinwealth_Jan20==11
				replace ofinJan20_midpt=187500 if ofinwealth_Jan20==12
				replace ofinJan20_midpt=225000 if ofinwealth_Jan20==13
				replace ofinJan20_midpt=325000 if ofinwealth_Jan20==14	// anni - i changed this from 275 to 325  //
				replace ofinJan20_midpt=575000 if ofinwealth_Jan20==15		 
				replace ofinJan20_midpt=. if ofinwealth_Jan20==.
				order ofinJan20_midpt, after(ofinwealth_Jan20)
				
				gen retirJan20_midpt=. 
				replace retirJan20_midpt=0 if retirwealth_Jan20==1
				replace retirJan20_midpt=500 if retirwealth_Jan20==2
				replace retirJan20_midpt=2500 if retirwealth_Jan20==3
				replace retirJan20_midpt=7500 if retirwealth_Jan20==4
				replace retirJan20_midpt=17500 if retirwealth_Jan20==5
				replace retirJan20_midpt=37500 if retirwealth_Jan20==6
				replace retirJan20_midpt=62500 if retirwealth_Jan20==7
				replace retirJan20_midpt=87500 if retirwealth_Jan20==8
				replace retirJan20_midpt=112500 if retirwealth_Jan20==9
				replace retirJan20_midpt=137500 if retirwealth_Jan20==10
				replace retirJan20_midpt=162500 if retirwealth_Jan20==11
				replace retirJan20_midpt=187500 if retirwealth_Jan20==12
				replace retirJan20_midpt=225000 if retirwealth_Jan20==13
				replace retirJan20_midpt=325000 if retirwealth_Jan20==14	// anni - i changed this from 275 to 325  //
				replace retirJan20_midpt=575000 if retirwealth_Jan20==15		
				replace retirJan20_midpt=. if retirwealth_Jan20==.
				order retirJan20_midpt, after(retirwealth_Jan20)
				
				
				sum retirJan20_midpt ofinJan20_midpt
				count if retirJan20_midpt !=. & retirJan20_midpt>0 | ofinJan20_midpt>0 & ofinJan20_midpt!=. // 2,031
				gen finwealth_Jan20=retirJan20_midpt+ofinJan20_midpt
				sum finwealth_Jan20 // 2,613
				la var finwealth_Jan20 "hh total fin wealth, retirement + other fin wealth as of Jan 2020"
				count if finwealth_Jan20>0 & finwealth_Jan20!=. //1,990, less than the 2,031 due to "Prefer not to say" in either component
				
				
				sum riskshare_retirwealth_Jan20
				gen x=riskshare_retirwealth_Jan20
				replace x=0 if retirwealth_Jan20==1
				replace x=. if retirwealth_Jan20==16
				sum retirJan20_midpt x
				
				gen y=riskshare_ofinwealth_Jan20
				replace y=0 if ofinwealth_Jan20==1
				replace y=. if ofinwealth_Jan20==16
				sum ofinJan20_midpt y
				
					
				gen riskshare_finwealth_Jan20=(retirJan20_midpt*x+ofinJan20_midpt*y)/finwealth_Jan20
				
				sum riskshare_finwealth_Jan20 //1,990 (needs to equal number of respondents with available fin wealth holdings)
				sum riskshare_finwealth_Jan20 riskshare_ofinwealth_Jan20  riskshare_retirwealth_Jan20
				
				order finwealth_Jan20 riskshare_finwealth_Jan20, after(riskshare_ofinwealth_Jan20)
				
				gen stockinvestor=0 
				replace stockinvestor=1 if riskshare_retirwealth>0 & riskshare_retirwealth!=.
				replace stockinvestor=1 if riskshare_ofinwealth>0 & riskshare_ofinwealth!=.
				label var stockinvestor "indicator=1 if respondent invests in stocks or stock mutual funds"
				order stockinvestor, after(riskshare_finwealth_Jan20)
				
				drop x y
				
				rename retirJan20_midpt retirewealth_lvl
				rename ofinJan20_midpt  ofinwealth_lvl
				
				sum ofinwealth_lvl, d
				gen h_ofinwealth_lvl=(ofinwealth_lvl>=r(p50))
				replace h_ofinwealth_lvl=. if ofinwealth_lvl==.
				tab h_ofinwealth_lvl, miss
				order h_ofinwealth_lvl, after(ofinwealth_lvl)
				
				
				foreach x in  riskshare_retirwealth_Jan20 riskshare_ofinwealth_Jan20 riskshare_finwealth_Jan20 {
				replace `x' = 100 if `x'>100 & `x'!=.
			}

			
			
			
			
			
			
			* 3.4) SHARES OF RETIREMENT WEALTH AND OTHER FINANCIAL WEALTH IN TOTAL FINANCIAL ASSETS 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
				gen share_retir_finwealth= retirewealth_lvl /finwealth_Jan20
				gen share_ofin_finwealth= ofinwealth_lvl/finwealth_Jan20
				
				sum share_retir_finwealth share_ofin_finwealth, d /// available for  5,835; 
				
					*~ set 0 for those with 0 financial wealth and missing for those who refuse to report wealth 
						
						gen finwealth_NR=ofinJan20_NR+retirJan20_NR
						replace finwealth_NR=1 if finwealth_NR==2
						tab finwealth_NR, miss
						
						
						foreach var of varlist share_retir_finwealth share_ofin_finwealth{
						
						replace `var'=0 if finwealth_Jan20==0
						replace `var'=. if finwealth_NR==1
						}
						*
				
				
				
				
			* 3.5) REAL ESTATE WEALTH AS OF JAN 2020
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
				
				order realestatejan debtjan netincome, after(riskshare_ofinwealth)

			/*What was the total value of the real estate your household owned at the end of
			January 2020, i.e. before the start of the current crisis? That is, without
			taking any outstanding loans into account, about how much would you have
			earned, had it been sold at the end of January 2020?*/

				rename realestatejan realestate_Jan20
				label define realest 1 "$0" 2 "$1 - $49,999" 3 "$50,000 - $99,999" ///
				4 "$100,000 - $199,999" 5 "$200,000 - $299,999" ///
				6 "$300,000 - $399,999" 7 "$400,000 - $499,999" ///
				8 "$500,000 - $749,999" 9 "$750,000 - $999,999" ///
				10 "$1,000,000 - $1,499,999" 11 "$1,500,000 and more" /// 
				13 "Prefer not to say." 
				
				label values realestate_Jan20 realest
				label variable realestate_Jan20 "total value of real estate hh owned at the end of January 2020"
				
				tab realestate_Jan20, gen (realestJan20_)
				order realestJan20_1- realestJan20_12, after(realestate_Jan20)
				
					rename realestJan20_1 realestJan20_0
					rename realestJan20_2 realestJan20_50k
					rename realestJan20_3 realestJan20_50k_100k
					rename realestJan20_4 realestJan20_100k_200k
					rename realestJan20_5 realestJan20_200k_300k
					rename realestJan20_6 realestJan20_300k_400k
					rename realestJan20_7 realestJan20_400k_500k
					rename realestJan20_8 realestJan20_500k_750k
					rename realestJan20_9 realestJan20_750k_1m
					rename realestJan20_10 realestJan20_1m_1m500k
					rename realestJan20_11 realestJan20_1m500k
					rename realestJan20_12 realestJan20_NR

					
					
					
					
					
			* 3.6) TOTAL HH DEBT AS OF JAN 2020 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
				rename debtjan debt_Jan20
				
				label define debt20 ///
				1 "$0" 2 "$1 - $999" 3 "$1,000 - $4,999" 4 "$5,000 - $9,999" ///
				5 "$10,000 - $24,999" 6 "$25,000 - $49,999" ///
				7 "$50,000 - $74,999" 8 "$75,000 - $99,999" 9 "$100,000 - $199,999" ///
				10 "$200,000 - $299,999" 11 "$300,000 - $499,999" 12 "$500,000 - $749,999" 13 "$750,000 and more" ///
				14 "Prefer not to say."
				label values debt_Jan20 debt20
				
				label var debt_Jan20 "Total household debt as of January 2020"
				
					tab debt_Jan20, generate(debtJan20_)
					order debtJan20_1-debtJan20_14, after(debt_Jan20)
					rename debtJan20_1 debtJan20_0
					rename debtJan20_2 debtJan20_1k
					rename debtJan20_3 debtJan20_1k_5k
					rename debtJan20_4 debtJan20_5k_10k
					rename debtJan20_5 debtJan20_10k_25k
					rename debtJan20_6 debtJan20_25k_50k
					rename debtJan20_7 debtJan20_50k_75k
					rename debtJan20_8 debtJan20_75k_100k
					rename debtJan20_9 debtJan20_100k_200k
					rename debtJan20_10 debtJan20_200k_300k
					rename debtJan20_11 debtJan20_300k_500k
					rename debtJan20_12 debtJan20_500k_750k
					rename debtJan20_13 debtJan20_750k
					rename debtJan20_14 debtJan20_NR

		

			* 3.7) TOTAL HH NET WEALTH  2019 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
			* gross wealth + housing equity - debt 
				  
			gen realestate_lvl = 0
			replace realestate_lvl = 0 if realestJan20_0==1
			replace realestate_lvl = 25000 if realestJan20_50k==1
			replace realestate_lvl = 75000 if realestJan20_50k_100k==1
			replace realestate_lvl = 150000 if realestJan20_100k_200k==1
			replace realestate_lvl = 250000 if realestJan20_200k_300k==1
			replace realestate_lvl = 350000 if realestJan20_300k_400k==1
			replace realestate_lvl = 450000 if realestJan20_400k_500k==1
			replace realestate_lvl = 625000 if realestJan20_500k_750k==1
			replace realestate_lvl = 875000 if realestJan20_750k_1m==1
			replace realestate_lvl = 1250000 if realestJan20_1m_1m500k==1
			replace realestate_lvl = 1750000 if realestJan20_1m500k==1	
				
			gen debt_lvl = 0
			replace debt_lvl = 0 if debtJan20_0==1
			replace debt_lvl = 500 if debtJan20_1k==1
			replace debt_lvl = 3000 if debtJan20_1k_5k==1
			replace debt_lvl = 7500 if debtJan20_5k_10k==1
			replace debt_lvl = 17500 if debtJan20_10k_25k==1
			replace debt_lvl = 37500 if debtJan20_25k_50k==1
			replace debt_lvl = 67500 if debtJan20_50k_75k==1
			replace debt_lvl = 87500 if debtJan20_75k_100k==1
			replace debt_lvl = 150000 if debtJan20_100k_200k==1
			replace debt_lvl = 250000 if debtJan20_200k_300k==1
			replace debt_lvl = 400000 if debtJan20_300k_500k==1
			replace debt_lvl = 625000 if debtJan20_500k_750k==1
			replace debt_lvl = 875000 if debtJan20_750k==1		 
					   
					   
			sum *_lvl		   
			gen netwealth_Jan20 = (retirewealth_lvl+ofinwealth_lvl+realestate_lvl)-debt_lvl
			sum netwealth_Jan20, d
			histogram netwealth_Jan20

			la variable netwealth_Jan20 "hh total net wealth as of Jan 2020"

			replace netwealth_Jan20=. if 	retirJan20_NR==1 | ofinJan20_NR==1 | ///
											realestJan20_NR==1 | debtJan20_NR ==1

							
											
			gen netwealth_Jan20_NR=(netwealth_Jan20==.)
			order netwealth_Jan20_NR, after(netwealth_Jan20)
			replace netwealth_Jan20=0 if netwealth_Jan20_NR==1


			
			* 3.8) HH GROSS INCOME  2019 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
			gen hhinc_lvl = 0  // DO we use that? 
			replace hhinc_lvl = 15000 if inc_15000==1			
			replace hhinc_lvl = 20000 if inc_15000_25000==1
			replace hhinc_lvl = 37500 if inc_25000_50000==1
			replace hhinc_lvl = 62500 if inc_50000_75000==1
			replace hhinc_lvl = 87500 if inc_75000_100000==1
			replace hhinc_lvl = 125000 if inc_100000_150000==1
			replace hhinc_lvl = 175000 if inc_150000_200000==1
			replace hhinc_lvl = 225000 if inc_200000==1 		
			replace hhinc_lvl = . if inc_NR==1

			
			
			* 3.9) HH NET INCOME  2019 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
			rename netincome hhnetinc_19

				label define hhnetinc_19 1 "$14,999 and less" 2 "$15,000 - $24,999" 3 "$25,000 - $49,999" ///
				4 "$50,000 - $74,999" 5 "$75,000 - $99,999" 6 "$100,000 - $149,999" 7 "$150,000 - $199,999" ///
				8 "$200,000 and more" 9 "Prefer not to say"
				
				label values hhnetinc_19 hhnetinc_19
				label variable hhnetinc_19 "total net income in 2019"
				
			tab hhnetinc_19, gen(hhnetinc19_)
			order hhnetinc19_1-hhnetinc19_9, after(hhnetinc_19)
			rename hhnetinc19_1  hhnetinc19_15k
			rename hhnetinc19_2 hhnetinc19_15k_25k
			rename hhnetinc19_3 hhnetinc19_25k_50k
			rename hhnetinc19_4 hhnetinc19_50k_75k
			rename hhnetinc19_5 hhnetinc19_75k_100k
			rename hhnetinc19_6 hhnetinc19_100k_150k
			rename hhnetinc19_7 hhnetinc19_150k_200k
			rename hhnetinc19_8 hhnetinc19_200k
			rename hhnetinc19_9 hhnetinc19_NR
			
			
			gen hhnetinc_19_midpt =.
			replace hhnetinc_19_midpt=15000 if hhnetinc_19==1
			replace hhnetinc_19_midpt=20000 if hhnetinc_19==2
			replace hhnetinc_19_midpt=37500 if hhnetinc_19==3
			replace hhnetinc_19_midpt=62500 if hhnetinc_19==4
			replace hhnetinc_19_midpt=87500 if hhnetinc_19==5
			replace hhnetinc_19_midpt=125000 if hhnetinc_19==6
			replace hhnetinc_19_midpt=175000 if hhnetinc_19==7
			replace hhnetinc_19_midpt=225000 if hhnetinc_19==8
			replace hhnetinc_19_midpt=0 if hhnetinc_19==9

			gen ln_hhnetinc=ln(hhnetinc_19_midpt+1)

			order hhnetinc_19_midpt ln_hhnetinc, after(hhnetinc19_NR)

			gen hhnetinc_2019= hhnetinc_19_midpt
			
			replace hhnetinc_2019 = . if hhnetinc19_NR==1	
	
	
	
	
			* 3.10) WEALTH AND INCOME BINS 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
	
			foreach x in  netwealth_Jan20  hhnetinc_2019 {
				xtile `x'_grp = `x'  if netwealth_Jan20_NR==0, nq(5)
			}
			*
			order netwealth_Jan20_grp, after(netwealth_Jan20)
			la var netwealth_Jan20_grp "Net wealth quintile"

			foreach x in  finwealth_Jan20   {
				xtile `x'_grp = `x' if retirJan20_NR==0 &  ofinJan20_NR==0, nq(5)
			}
			*
			order finwealth_Jan20_grp , after(finwealth_Jan20)
			la var finwealth_Jan20_grp "Financial wealth quintile"

				
			foreach x in   retirewealth ofinwealth realestate debt hhinc {
				xtile `x'_grp = `x'_lvl, nq(5)
				order `x'_grp , after(`x'_lvl)
			}
			*
			la var retirewealth_grp "Retirement wealth quintile"
			la var ofinwealth_grp "Other financial wealth quintile"
			la var realestate_grp "Real estate wealth quintile"
			la var debt_grp "Debt quintile"
			la var hhinc_grp "Gross income quintile"






************************
************************
************************
drop if finwealth_NR==1
count

sum retirewealth_lvl ofinwealth_lvl

** 4) WEALTH AND INCOME LOSSES 
********************************************
		

	*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	* 4.1) RETIREMENT WEALTH LOSSES/LOSSES IN OTHER FINANCIAL WEALTH 
	*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

			
			* 4.1.1) RETIREMENT WEALTH LOSSES 
			********************************************************************
			
			
					/*Overall, would you say that the combined value of all your householdӳ
					retirement accounts, including 401(K)s, IRAs, or Keogh accounts, has
					decreased due to the recent drop in stock prices?*/
							
						tab lossretir, miss
						replace lossretir=0 if lossretir==2 & lossretir!=.
						label define yesno 1 "yes" 0 "no"
						label values lossretir yesno 
						label variable lossretir "indicator =1 if respondent incurred a loss of retirement wealth"
						
					/*By about what percent did the combined value of your household's retirement
					accounts decrease as a result of the recent stock market decline since January,
					before the start of the current crisis, as of today?*/

						rename loss_ret_perc lossretir_perc
						label variable lossretir_perc "retirement wealth losses in percent"
						
					/*Overall, would you say that the combined value of all of your householdӳ
					retirement accounts has increased due to the recent stock market
					developments since January, for example because your household invested in
					stocks that have increased in value?*/

						rename lossretirrout2 gainretir
						replace gainretir=0 if gainretir==2 & gainretir!=.
						label values gainretir yesno 
						label variable gainretir "indicator =1 if respondent incurred a gain in retirement wealth"
						
					/*Considering all of your householdsҠretirement accounts, by about what
					percent did the combined value of these accounts increase as a result of the
					recent stock market developments since January, before the start of the current
					crisis, as of today?*/	

						rename gain_ret_per gainretir_perc
						label variable gainretir_perc "retirement wealth gains in percent"
						label variable gainretir_perc "retirement wealth gains in percent"

					
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
			*~ calculate percentage change in retirement wealth 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

					tab retirwealth_Jan20 if retirJan20_NR==0 & retirwealth_Jan20>1 //5,134
					tab lossretir  // only asked if positive retirement wealth (5,584) 
					sum retirewealth_lvl if retirewealth_lvl>0 // available for 5,134;450 who prefer NR =5,584
					tab gainretir // only asked if lossretir==0 /// 1,132
					
					
					
					*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
					gen del_retir_perc=. 
					order del_retir_perc, before(lossretir)
					
					replace del_retir_perc	= 	-lossretir_perc 	if  lossretir==1 
					replace del_retir_perc	=	gainretir_perc  	if  lossretir==0 &  gainretir==1
					replace del_retir_perc	=	0 					if  lossretir==0 & 	gainretir==0
					sum del_retir_perc
					replace del_retir_perc 	= 	0 					if 	retirewealth_lvl==0 
					
					sum del_retir_perc
					count
					*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
					
					* inspect
					br del_retir_perc- gainretir_perc
					
					sum del_retir_perc, d // have some outliers here... so far always used variables trimmed at 2 percent
					
					
					
					
					
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
			*~ calculate USD change in retirement wealth 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

					gen delretir_USD=(del_retir_perc/100)*retirewealth_lvl 
					replace delretir_USD=. if retirewealth_lvl==. 
					replace delretir_USD=0 if retirewealth_lvl==0
					
					
					* inspect 
					*binscatter delretir_USD retirewealth_lvl
					
			
			
			/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
			*~ 	express losses to retirement wealh in terms of 
			*	overall financial wealth 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	

				gen del_retir_oftot=share_retir_finwealth*del_retir_perc
				replace del_retir_oftot=. if del_retir_perc==. | retirewealth_lvl==. | retirewealth_lvl==0
					
			*/ 	
	
	
	
			foreach var of varlist  delretir_USD del_retir_perc{
					
					replace `var'=. if finwealth_NR==1
					}
					*
					
					
			
				
			* 4.1.2) OTHER FINANCIAL WEALTH LOSSES 
			********************************************************************
			
			
				/*Overall, would you say that the combined value of all your householdӳ other
				investable financial assets (outside of retirement accounts, such as bank
				accounts, brokerage accounts, etc.) has decreased due to the recent drop in
				stock prices?*/
					
					rename q133 lossofin
					replace lossofin=0 if lossofin==2 & lossofin!=.
					label values lossofin yesno 
					label variable lossofin "indicator =1 if respondent incurred a loss of other financial wealth"
					
					
				/*By about what percent did the value of your householdӳ other investable
				financial assets (outside of retirement accounts) decrease as a result of the
				recent stock market decline since January, before the start of the current crisis,
				as of today?*/
					
					rename finloss lossofin_perc
					label variable lossofin_perc "other financial wealth losses in percent"

				/*Overall, would you say that the combined value of all your householdӳ other
				investable financial assets (outside of retirement accounts) has increased due
				to the recent stock market developments since January, for example because
				your household invested in stocks that have increased in value?*/

					rename q135 gainofin
					replace gainofin=0 if gainofin==2 & gainofin!=.
					label values gainofin yesno 
					label variable gainofin "indicator =1 if respondent incurred a gain on other financial wealth"
					
					
				/*By about what percent did the value of your householdsҠother investable
				financial assets (outside of retirement accounts) increase as a result of the
				recent stock market developments since January, before the start of the current
				crisis, as of today?*/

					rename fingain gainofin_perc
					label variable gainofin_perc "other financial wealth gains in percent"

				

						tab ofinwealth_Jan20 if ofinwealth_Jan20>1 
						tab lossofin //only asked if positive other financial wealth (2,196)
						tab gainofin // only asked if lossofin==0 
						sum ofinwealth_lvl if ofinwealth_lvl>1 

						
				
						
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
			*~ calculate percentage change in other financial wealth 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

					tab ofinwealth_Jan20 if ofinJan20_NR==0 & ofinwealth_Jan20>1 //5,436
					tab lossofin  // only asked if positive other fin wealth (5,835)
					tab ofinJan20_NR //399 prefer not to report other financial wealth 
					sum ofinwealth_lvl if ofinwealth_lvl>0 // available for 5,436;399 who prefer NR =5,835
					tab gainofin // only asked if lossretir==0 /// 1,132
					
					
					
					*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
					gen del_ofin_perc=. 
					order del_ofin_perc, before(lossofin)
					
					replace del_ofin_perc	= 	-lossofin_perc 	if  lossofin==1 
					replace del_ofin_perc	=	gainofin_perc  	if  lossofin==0 &  gainofin==1
					replace del_ofin_perc	=	0 				if  lossofin==0 &  gainofin==0
					
					sum del_ofin_perc
					replace del_ofin_perc	= 	0 				if 	ofinwealth_lvl==0 
					
				
					*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
					
					* inspect
					br del_ofin_perc- gainofin_perc
					
					sum del_ofin_perc, d // have some outliers here... so far always used variables trimmed at 2 percent
					
					
				
				
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
			*~ calculate USD change in other financial wealth 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

					gen delofin_USD=(del_ofin_perc/100)*ofinwealth_lvl 
					replace delofin_USD=. if ofinwealth_lvl==. 
					replace delofin_USD=0 if ofinwealth_lvl==0
				
					
					* inspect 
					*binscatter delofin_USD_tr02 ofinwealth_lvl
					
					
					
			foreach var of varlist  delofin_USD del_ofin_perc{
					
					replace `var'=. if finwealth_NR==1
					}
					*
					
					
					
					
					
			* 4.1.3) COMBINED FINANCIAL WEALTH LOSSES 
			********************************************************************		
					
				
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
			*~ calculate USD change in total financial wealth 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					sum delretir_USD delofin_USD
					gen delfinwealth_USD = delretir_USD+delofin_USD
					
					
					foreach var of varlist delfinwealth_USD delofin_USD delretir_USD{
					
					replace `var'=. if finwealth_NR==1
					}
					*
											
					sum delfinwealth_USD delofin_USD delretir_USD 
					
					
					/*replace delfinwealth_USD = delofin_USD if delretir_USD==. & delofin_USD!=.
					replace delfinwealth_USD = delretir_USD if delofin_USD==. & delretir_USD!=.
					*/
					sum delfinwealth_USD  
				
					
					
					
		
			
			/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
			*~ 	express losses to other financial wealth in terms of 
			*	overall financial wealth 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
				gen del_ofin_oftot=share_ofin_finwealth*del_ofin_perc
				replace del_ofin_oftot=. if del_ofin_perc==. | ofinwealth_lvl==. | ofinwealth_lvl==0
				
			*/			
				
				
		* 4.1.3) LOSSES  TO TOTAL FINANCIAL WEALTH 
		********************************************************************	
			
			sum retirewealth_lvl ofinwealth_lvl finwealth_Jan20
			tab finwealth_NR // 5798 fully report financial wealth 
			
			count if finwealth_Jan20 >0 & finwealth_NR==0 // 5,942 have positive financial wealth 
			
			*gen x=retirewealth_lvl+ ofinwealth_lvl
			*sum finwealth_Jan20 x						// equivalent!
			
			
			
			
			*gen del_finwealth_perc=(delretir_USD+delofin_USD)/finwealth_Jan20
			gen del_finwealth_perc=(delretir_USD+delofin_USD)/finwealth_Jan20
			* set change in financial wealth = 0 for those with zero financial wealth 
					replace del_finwealth_perc=0 if finwealth_Jan20==0
			* set change in financial wealth = . for those with incompletely reported financial wealth 
					replace del_finwealth_perc=. if finwealth_NR==1
			* express in ppt 
			replace del_finwealth_perc=100*del_finwealth_perc
			sum del_finwealth_perc, d //7,598
			
			
			gen w_retir=retirewealth_lvl/( ofinwealth_lvl+retirewealth_lvl)
			replace w_retir=0 if ofinwealth_lvl+retirewealth_lvl==0
			replace w_retir=0 if retirewealth_lvl==0
			
			gen w_ofin= (ofinwealth_lvl/(ofinwealth_lvl+retirewealth_lvl))
			replace w_ofin=0 if ofinwealth_lvl+retirewealth_lvl==0
			replace w_ofin=0 if ofinwealth_lvl==0
			
			gen w_check=w_retir+w_ofin
			tab w_check
			
				
			gen del_finwealth_perc_alt2=w_retir*del_retir_perc +w_ofin*del_ofin_perc
			
			bysort ofinwealth_grp: sum del_finwealth_perc_alt del_retir_perc del_ofin_perc
			
			
			
			
			gen x= del_finwealth_perc-del_retir_perc
			gen y= del_finwealth_perc-del_ofin_perc
			
			
			bysort ofinwealth_grp: sum del_finwealth_perc_alt del_retir_perc del_ofin_perc
			br ofinwealth_lvl retirewealth_lvl w_ofin w_retir  del_ofin_perc del_retir_perc del_finwealth_perc ///
			if (del_finwealth_perc< del_retir_perc) &  (del_finwealth_perc<del_ofin_perc) & netwealth_Jan20_grp<3
	
			foreach var of varlist x y {
			gen abs_`var'=abs(`var') 
			}
			*
			
			sum abs_x, d
			
			gen del_finwealth_round=round(del_finwealth_perc)
			gen del_ofin_perc_round=round(del_ofin_perc)
			gen del_retir_perc_round=round(del_retir_perc)
			
			
			
			gen abs_del_ofin_perc =abs(del_ofin_perc )
			gen abs_del_retir_perc =abs(del_retir_perc )
	   
	   gen z=( w_retir*del_retir_perc_round+w_ofin*del_ofin_perc_round== del_finwealth_round)
	   
	   gen o=( w_retir*del_retir_perc+w_ofin*del_ofin_perc== del_finwealth_perc)
	   
	   
	   br ofinwealth_lvl  w_ofin del_ofin_perc  retirewealth_lvl w_retir   del_retir_perc   del_finwealth_perc if ///
	   (del_retir_perc==0 & del_ofin_perc!=0) | (del_retir_perc!=0 & del_ofin_perc==0)
	   
	   
	   
	   
	   keep if   (del_retir_perc==0 & del_ofin_perc!=0) | (del_retir_perc!=0 & del_ofin_perc==0)
	   
	   gen n=_n
	   br if n<40
	   
	br ofinwealth_lvl  w_ofin del_ofin_perc  retirewealth_lvl w_retir   del_retir_perc   del_finwealth_perc if ///
	   (del_retir_perc==0 & del_ofin_perc!=0) | (del_retir_perc!=0 & del_ofin_perc==0) 
	   
 gen wrong=(del_finwealth_perc<del_ofin_perc& del_finwealth_perc<del_retir_perc)
	   capture drop x
	   gen x=del_finwealth_perc
	   format x %9.2f
	   
	gen abs_del=abs(del_finwealth_perc_alt)
 	
		
	
	bysort netwealth_Jan20_grp:  sum del_retir_perc del_ofin_perc del_finwealth_perc_alt 
	
	
		*** CHECK AVAILABILITY OF LOSS VARIABLES // 
		*******************************************
		
				replace ofinwealth_lvl = . if ofinwealth_Jan20==16
				replace retirewealth_lvl= . if retirwealth_Jan20==16
				replace finwealth_Jan20 = . if retirwealth_Jan20==16
				replace finwealth_Jan20 = . if ofinwealth_Jan20==16
				replace del_finwealth_perc = . if finwealth_Jan20==.
				replace delretir_USD = . if retirwealth_Jan20==16
				replace delofin_USD = . if ofinwealth_Jan20==16
				
				* set delta variables to zero if no financial holdings:
				replace del_finwealth_perc = 0 if finwealth_Jan20==0
				replace del_ofin_perc = 0 if ofinwealth_Jan20==1  & finwealth_NR!=1
				replace del_retir_perc = 0 if retirwealth_Jan20==1 & finwealth_NR!=1
			
			
				replace delofin_USD = 0 if ofinwealth_Jan20==1 & finwealth_NR!=1
				replace delretir_USD = 0 if retirwealth_Jan20==1 & finwealth_NR!=1
				
				replace del_ofin_perc=. if del_finwealth_perc==.
				replace del_retir_perc=.  if del_finwealth_perc==.
				
				* is this right? i think so... 
				
				replace delofin_USD=. if delfinwealth_USD==.
				replace delretir_USD=.  if delfinwealth_USD==.
				
		
			sum delfinwealth_USD delofin_USD delretir_USD if ofinwealth_lvl==0 & retirewealth_lvl  !=0
			sum del_retir_perc del_ofin_perc del_finwealth_perc if ofinwealth_lvl==0 & retirewealth_lvl  !=0
			
			
	
	*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	* 4.2) NET INCOME LOSSES 
	*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	
					

				/*Was the total net income of all members of your household (including you)
				since the beginning of 2020 higher or lower than you had expected at the
				beginning of the year, i.e. before the start of the current crisis?*/

					rename incloss1 incdiff_20q1
					tab incdiff_20q1, miss
					label variable incdiff_20q1 "total hh net income surprise during Q1 2020"
					label define diff 1 "Higher than expected" 2 "Lower than expected" 3 "About as expected"
					label values incdiff_20q1 diff

				/*By about what percent was your householdӳ net income higher than what you
				had expected? Please give your best guess.
				*/
					rename incgain incgain_20q1
					label variable incgain_20q1 "positive hh net income surprise Q1 2020 (in percent)"

				/*By about what percent was your householdӳ net income lower than what you
				had expected? Please give your best guess.*/

					rename incloss	incloss_20q1
					label variable incloss_20q1 "negative hh net income surprise Q1 2020 (in percent)"
					
					
					
							
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
			*~ calculate percentage change in hh net income 
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
						tab incdiff_20q1 , miss // available for all
						*replace incloss_20q1 = incloss_20q1*100 if incloss_20q1<1 & incloss_20q1!=.
						*replace incgain_20q1 = incgain_20q1*100 if incgain_20q1<1 & incgain_20q1!=.
						sum incgain_20q1, d  // only asked if positive income gain expected  
						sum incloss_20q1, d  // only asked if income loss expected
						replace incloss_20q1 = . if incloss_20q1>100 & incloss_20q1!=. 
						replace incgain_20q1 = . if incgain_20q1>100 & incgain_20q1!=. 
						
						gen del_hhnetinc_perc=. 
						replace del_hhnetinc_perc= -incloss_20q1 if  incdiff_20q1==2 
						replace del_hhnetinc_perc= incgain_20q1 if incdiff_20q1==1
						replace del_hhnetinc_perc=0 if incdiff_20q1==3
						
						replace del_hhnetinc_perc = . if hhnetinc19_NR==1

						br incdiff_20q1 incgain_20q1 incloss_20q1 del_hhnetinc_perc
						sum del_hhnetinc_perc, d
						
																
						
						
						
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
			*~ calculate USD change in HH net income
			*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					
						
					gen delhhnetinc_USD = (del_hhnetinc_perc/100)*hhnetinc_2019
					
					br delhhnetinc_USD if hhnetinc19_NR==1
					
	*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
	* 4.3) LOSS BINS 
	*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

				* make delta-group variables such that 5 = highest loss, 1 = highest gain
					sum del_finwealth_perc, d
					gen del_finwealth_percNeg = -del_finwealth_perc
					
					sum del_ofin_perc, d
					gen del_ofin_percNeg = -del_ofin_perc
					sum del_retir_perc, d
					gen del_retir_percNeg = -del_retir_perc
					sum del_hhnetinc_perc, d
					gen del_hhnetinc_percNeg = -del_hhnetinc_perc
					
				* make groups for variables with lots of bunching:
					foreach x in del_ofin del_retir  del_finwealth  del_hhnetinc {
						sort `x'_perc
						gen `x'_alt = int(5*(_n-1)/_N)+1 if `x'_perc!=.
						xtile `x'_grp = `x'_perc, nq(5)
					}
				* make groups for variables with lots of bunching:
					foreach x in del_finwealth_percNeg del_hhnetinc_percNeg  {
						sort `x'
						gen `x'_alt = int(5*(_n-1)/_N)+1 if `x'!=.
						xtile `x'_grp = `x', nq(5)
					}		
				* make groups for variables with lots of bunching:
					foreach x in del_ofin_percNeg del_retir_percNeg {
						sort `x'
						gen `x'_alt = int(6*(_n-1)/_N)+1 if `x'!=.
						xtile `x'_grp = `x', nq(6)
					}			
					
					
				tab del_hhnetinc_percNeg_alt
				tab del_hhnetinc_percNeg_grp
				tab del_finwealth_percNeg_grp
				tab del_finwealth_percNeg_alt
				
				tab del_ofin_percNeg_alt 
				tab del_ofin_percNeg_grp 
				
				tab del_retir_percNeg_alt 
				tab del_retir_percNeg_grp
				
				
				
				*replace del_finwealth_percNeg_grp = del_finwealth_percNeg_alt
				replace del_hhnetinc_percNeg_grp = del_hhnetinc_percNeg_alt
				replace del_ofin_percNeg_grp = del_ofin_percNeg_alt
				replace del_retir_percNeg_grp = del_retir_percNeg_alt

				
				
	
				
				
				
				
** 5) PRIOR BELIEFS
********************************************

/*What do you think, how many years did it take until US stock prices had
recovered to their pre-crisis level (starting from the beginning of the drop in
stock prices in October 2007)?*/

	sum prior prior_dotcom prior_blackmonday
	order prior_dotcom prior_blackmonday, after(prior)
	rename prior prior_fincrisis
	
	gen prior=.
	order prior, befor(prior_fincrisis)
	
	foreach var of varlist prior_fincrisis prior_dotcom prior_blackmonday {
	replace prior=`var' if `var'!=.
	}
	*
	
	label variable prior "prior estimate of # of years until stock market recovery"
	label variable prior_fincrisis "prior estimate of # of years until recovery fin. crisis treatment"
	label variable prior_dotcom "prior estimate of # of years until recovery dotcom treatment"
	label variable prior_blackmonday "prior estimate of # of years until recovery Black Monday treatment"
	drop q231_firstclick- q233_clickcount
	
	
	* top-code prior at 13 years 
	
	sum prior, d
	replace prior = 13 if prior>13 & prior!=.
	
	
******
******	







** 6) POSTERIOR/MANIPULATION CHECKS
********************************************
	
/*What do you think, in which calendar year will the US stock market have
recovered to the level of January 2020 (the level before the recent drop in
stock prices)?*/

	label variable posterior "posterior estimate of calendar year of stock market recovery"
	
	gen recovery_duration = (posterior-2020)
	order recovery_duration, after(posterior)
	label variable recovery_duration "inferred posterior estimate of length of stock market recovery in years"
	


	** turn around scale for manipulation checks 1 - fully disagree, 7 - fully agree

	foreach var of varlist  manip1 manip2 manip3 {
	gen 	x`var'=1 if `var'==7
	replace x`var'=2 if `var'==6
	replace x`var'=3 if `var'==5
	replace x`var'=4 if `var'==4
	replace x`var'=5 if `var'==3
	replace x`var'=6 if `var'==2
	replace x`var'=7 if `var'==1
	order x`var', after(`var')
	}
	*
	
	br manip1-xmanip3
	drop manip1 manip2 manip3
	
	rename xmanip1 manip1 
	rename xmanip2 manip2 
	rename xmanip3 manip3
	
	/*"The outbreak of the coronavirus will keep US stock prices below their January
	2020 levels for many years."*/

	label variable manip1 "agree: coronavirus will keep stock prices below Jan 2020 levels for many years."
	*gen h_manip1=(manip1<=3)
	*order h_manip1, after(manip1)
	*label var h_manip1 "indicator=1 if disagreement on manip1 < median"
	
/*"The outbreak of the coronavirus has set the level of the stock market back by
many years."*/

	label variable manip2 "agree: coronavirus has set stock prices back by many years."
	*tab manip2
	*gen h_manip2=(manip1<=3)
	*order h_manip2, after(manip2)
	*label var h_manip2 "indicator=1 if disagreement on manip2 < median"
	
/*"The US stock market will have recovered by the end of the year 2020."*/
	
	label variable manip3 "agree: stock market will have recovered by the end of 2020."
	*tab manip3
	*gen h_manip3=(manip1<=4)
	*order h_manip3, after(manip3)
	*label var h_manip3 "indicator=1 if disagreement on manip3 < median"
	


/*What do you think, in which calendar year will your own householdӳ net
wealth have recovered to the level of January 2020?
*/
	br manip_ownwealth manip_ownwealth_7_text
	replace manip_ownwealth_7_text=9999 if manip_ownwealth==8
	drop manip_ownwealth
	rename manip_ownwealth_7_text manip_ownwealth 
	label variable manip_ownwealth "posterior estimate of calendar year in which own wealth recovers; 9999 if never"

	gen recov_hhwealth_duration=(manip_ownwealth-2020)
	replace recov_hhwealth_duration=. if manip_ownwealth==9999 |manip_ownwealth==.
	order recov_hhwealth_duration, after(manip_ownwealth)
	label variable recov_hhwealth_duration "inferred posterior estimate of # years until hh wealth recovers"
	
	


/*What do you think, in which calendar year will your own householdӳ net income have recovered 
to the level of 2019?*/	
	
	order owninc_year_7_text owninc_year, after(recov_hhwealth_duration)

	replace owninc_year_7_text =9999 if owninc_year==8 & owninc_year!=.
	drop owninc_year
	rename owninc_year_7_text manip_owninc
	label variable manip_owninc "posterior estimate of year in which hh net income recovers; 9999 if never"

	gen recov_owninc_duration=(manip_owninc-2020)
	replace recov_owninc_duration=. if manip_owninc==9999 |manip_owninc==.
	order recov_owninc_duration, after(manip_owninc)
	label variable recov_owninc_duration "inferred posterior estimate of # years until pers income recovers"

	
	


******
******	


** 7) POSTERIOR EXPECTATIONS 
********************************************

 /*In this question we present you with eight possible scenarios for the US stock
market return over the next 12 months.

Please let us know what probability you attach to each scenario. The
probabilities of the eight scenarios need to sum to 100 percent.

Probability (in percent) that the US stock market return will be ...
... less than -30 percent 0
... between -30 and -15 percent 0
... between -15 and -5 percent 0
... between -5 and 0 percent 0
... between 0 and 5 percent 0
... between 5 and 15 percent 0
... between 15 and 30 percent 0
... greater than 30 percent
*/

rename stockret_distr_1 retdist_neg30
label variable retdist_neg30 "subj. dist.: probability of return being -30% or lower"
rename stockret_distr_2 retdist_neg30_15
label variable retdist_neg30_15 "subj. dist.: probability of return being -30% to -15%"
rename stockret_distr_3 retdist_neg15_5
label variable retdist_neg15_5 "subj. dist.: probability of return being -15% to -5%"
rename stockret_distr_4 retdist_neg5_0
label variable retdist_neg5_0 "subj. dist.: probability of return being -5% to 0%"
rename stockret_distr_5 retdist_pos0_5
label variable retdist_pos0_5 "subj. dist.: probability of return being 0% to 5%"
rename stockret_distr_6 retdist_pos5_15
label variable retdist_pos5_15 "subj. dist.: probability of return being 5% to 15%"
rename stockret_distr_7 retdist_pos15_30
label variable retdist_pos15_30 "subj. dist.: probability of return being 15% to 30%"
rename stockret_distr_8 retdist_pos30
label variable retdist_pos30 "subj. dist.: probability of return being 30% or higher"


/*In general, do you think your household will be financially better or worse off 12
months from now than you are these days?*/

rename prospecthh finprospect

label define prospect ///
1 "Much worse off" 2 "Worse off" 3 "Somewhat worse off" ///
4 "About the same" 5 "Somewhat better off" 6 "Better off" 7 "Much better off"

label values finprospect prospect
label variable finprospect "expectation on hh relative financial situation 12 months after survey date." 

	gen finprospect_mwors=(finprospect==1 & finprospect!=.)
	la var finprospect_mwors "indicator =1 if fin. situation expected to worsen a lot over next 12m"
	gen finprospect_wors=(finprospect<=3 & finprospect!=.)
	la var finprospect_wors "indicator =1 if fin. situation expected to worsen over next 12m"
	gen finprospect_mbet=(finprospect==7 & finprospect!=.)
	la var finprospect_mbet "indicator =1 if fin. situation expected to improve a lot over next 12m"
	gen finprospect_bet=(finprospect>=5 & finprospect!=.)
	la var finprospect_bet "indicator =1 if fin. situation expected to improve over next 12m"
	order finprospect_mwors -finprospect_bet, after(finprospect)
	
	

******
******	


** 8) OTHER OUTCOMES 
********************************************

** HH TOTAL SPENDING 

/*Compared to 2019, I expect my total household spending in the year 2020 to
be...
		... higher.
		... lower.
		... about the same.*/

	rename q146 spendiff_2020
	label define diff20 1 "Higher compared to 2019" 2 "lower compared to 2019" 3 "about the same than in 2019" 
	label values spendiff diff20
	label variable spendiff_2020 "Household total spending in 2020 compared to 2019"
	
	tab spendiff_2020, gen(spendiff20_)
	order spendiff20_1 spendiff20_2 spendiff20_3, after(spendiff_2020)
	rename spendiff20_1 spendiff20_higher
	rename spendiff20_2 spendiff20_lower
	rename spendiff20_3 spendiff20_same
	
	*~ recode to have in sync with other outcomes  
	
	gen expec_spend3=.
	replace expec_spend3=1 if spendiff_2020==1
	replace expec_spend3=2 if spendiff_2020==3
	replace expec_spend3=3 if spendiff_2020==2
	
	label define change3 1 "increase" 2 "no change" 3 "decrease"
	label values expec_spend3 change3
	order expec_spend3, after(spendiff_2020)
	

	
	*~ expected percentage change in spending
	
	rename spendhigher spendhigher20_perc
	label variable spendhigher20_perc "Increase in household total spending in 2020 compared to 2019 in percent"
	
	rename spendlower spendlower20_perc
	label variable spendlower20_perc "Decrease in household total spending in 2020 compared to 2019 in percent"

	
	
	gen del_spend20_perc=. 
	replace del_spend20_perc=spendhigher20_perc if  spendiff_2020==1
	replace del_spend20_perc=-spendlower20_perc if  spendiff_2020==2
	replace del_spend20_perc=0 if  spendiff_2020==3
	sum del_spend20_perc, d
	
	*~ remove outliers 
		

	
** HH NET INCOME 

/*Compared to 2019, I expect my total net household income in 2020 to be�

	... higher.
	... lower.
	... about the same.*/

	rename netincrout netincdiff_2020
	label values netincdiff_2020 diff20
	label variable netincdiff_2020 "Household total net household income in 2020 compared to 2019"
	

	tab netincdiff_2020, gen(netincdiff20_)
	order netincdiff20_1 -netincdiff20_3, after(netincdiff_2020)
	rename netincdiff20_1 netincdiff20_higher
	rename netincdiff20_2 netincdiff20_lower
	rename netincdiff20_3 netincdiff20_same
	
	
/*
By about what percent do you expect your total net household income to be
higher? Please give your best guess.*/

	rename incgain2020 netinchigher20_perc
	label variable netinchigher20_perc "Increase in hh total net household income in 2020 compared to 2019 in percent"
	
/*By about what percent do you expect your total net household income to be
lower? Please give your best guess.
*/
	rename incloss2020 netinclower20_perc
	label variable netinclower20_perc "Decrease in hh total net household income in 2020 compared to 2019 in percent"

	gen del_hhnetinc_exp20=.
	replace del_hhnetinc_exp20=netinchigher20_perc if netinchigher20_perc!=.
	replace del_hhnetinc_exp20=-netinclower20_perc if netinclower20_perc!=.
	replace del_hhnetinc_exp20=0 if netincdiff_2020==3
	order del_hhnetinc_exp20, after(netincdiff_2020)
	br netincdiff_2020-netinclower20_perc


** LABOR & RETIREMENT DECISIONS 

/*How are your expectations regarding your retirement age affected by the
current crisis?
		I will certainly retire later than I had expected before the crisis.
		I may retire later than I had expected before the crisis.
		Not affected.
		I may retire earlier than I had expected before the crisis.
		I will certainly retire earlier than I had expected before the crisis.
*/

label define retirage 	1 "certainly retire later" 2 "may retire later" ///
						3 "retirement age unaffected" 4 "may retire earlier" ///
						5 "certainly retire earlier"

	label values expec_retireage retirage
	label variable expec_retireage "impact on expectations regarding desired retirement age"
	
	gen expec_retirlater=(expec_retireage==1& expec_retireage!=. |expec_retireage==2 & expec_retireage!=.)
	la var expec_retirlater "indicator =1 if respondent expects to retire later due to crisis"
	gen expec_retirearly=(expec_retireage==4& expec_retireage!=. |expec_retireage==5 & expec_retireage!=.)
	la var expec_retirearly "indicator =1 if respondent expects to retire earlier due to crisis"
	order expec_retirlater expec_retirearly, after(expec_retireage)
	
	*~ generate 3-outcome measure (increase/no change/decrease) to have it in same format with other outcomes 
	
	
	gen expec_retireage3=.
	replace expec_retireage3=1 if expec_retireage==1|expec_retireage==2
	replace expec_retireage3=2 if expec_retireage==3
	replace expec_retireage3=3 if expec_retireage==4|expec_retireage==5
	label values expec_retireage3 change3
	order expec_retireage3, after(expec_retirearly)
	
				
/* How are your expectations regarding your desired working hours in the next
   years affected by the current crisis?
		I will certainly try to work more than I had expected before the crisis.
		I may try to work more than I had expected before the crisis.
		Not affected.
		I may try to work less than I had expected before the crisis.
		I will certainly try to work less than I had expected before the crisis.
*/ 

	label define hours 	1 "certainly try to work more" 2 "may try to work more" ///
						3 "desired hours worked unaffected" 4 "may try to work less" ///
						5 "certainly will try to work less"

	label values expec_desiredhours hours
	label variable expec_desiredhours "impact on expectations regarding desired working hours"

	gen expec_morehrs=(expec_desiredhours==1& expec_desiredhours!=. |expec_desiredhours==2 & expec_desiredhours!=.)
	la var expec_morehrs "indicator =1 if respondent expects to work more hours due to crisis"
	gen expec_lesshrs=(expec_desiredhours==4& expec_desiredhours!=. |expec_desiredhours==5 & expec_desiredhours!=.)
	la var expec_lesshrs "indicator =1 if respondent expects to work less hours due to crisis"
	order expec_morehrs expec_lesshrs, after(expec_desiredhours)
	
	*~ generate 3-outcome measure (increase/no change/decrease) to have it in same format with other outcomes 
	
	gen expec_desiredhours3=.
	replace expec_desiredhours3=1 if expec_desiredhours==1|expec_desiredhours==2
	replace expec_desiredhours3=2 if expec_desiredhours==3
	replace expec_desiredhours3=3 if expec_desiredhours==4|expec_desiredhours==5
	label values expec_desiredhours3 change3
	order expec_desiredhours3, after(expec_lesshrs)

** HOUSEHOLD DEBT 

/*How are your expectations regarding your householdӳ total debt (including
mortgage debt, credit card balances, etc.) that will be outstanding at the end of
2020 affected by the current crisis?

	My householdӳ debt will be a lot higher than I had expected before the crisis.
	My householdӳ debt will be somewhat higher than I had expected before the crisis.
	Not affected.
	My householdӳ debt will be somewhat lower than I had expected before the crisis.
	My householdӳ debt will be a lot lower than I had expected before the crisis.*/

	rename debt expec_debt
	label define expec_debt	4 "a lot higher than expected" 5 "somewhat higher than expected" ///
						6 "as expected" 7 "somewhat lower than expected" ///
						8 "a lot lower than expected"

	label values expec_debt expec_debt
	label variable expec_debt "impact on expectations regarding hh total debt"

	gen expec_debthigher=(expec_debt==4 & expec_debt!=. |expec_debt==5 & expec_debt!=.)
	la var expec_debthigher "indicator =1 if respondent expects to work more hours due to crisis"
	gen expec_debtlower=(expec_debt==7& expec_debt!=. |expec_debt==8 & expec_debt!=.)
	la var expec_debtlower "indicator =1 if respondent expects to work less hours due to crisis"
	order expec_debthigher expec_debtlower, after(expec_debt)
	
	foreach var of varlist expec_debthigher expec_debtlower {
	replace `var'=. if expec_debt==.
	}
	*
	
	*~ generate 3-outcome measure (increase/no change/decrease) to have it in same format with other outcomes 
	gen expec_debt3=.
	replace expec_debt3=1 if expec_debt==4|expec_debt==5
	replace expec_debt3=2 if expec_debt==6
	replace expec_debt3=3 if expec_debt==7|expec_debt==8
	label values expec_debt3 change3
	
	
	
** STOCK INVESTMENT DECISIONS 

* investment decisions already realized 

	/*Which of the following describes your household's recent actions best?

		My household has actively, through purchases and sales of stocks or stock
		mutual funds,ō
		
		Šstrongly increased the share of stocks/stock mutual funds in financial wealth.
		Šincreased the share of stocks/stock mutual funds in financial wealth.
		Šsomewhat increased the share of stocks/stock mutual funds in financial wealth.
		Šsomewhat decreased the share of stocks/stock mutual funds in financial wealth.
		Šdecreased the share of stocks/stock mutual funds in financial wealth.
		Šstrongly decreased the share of stocks/stock mutual funds in financial wealth.
		My household has not made any active adjustments to the share of
		stocks/stock mutual funds in financial wealth.
	*/ 

	rename traderealized stocktrades_realized
	label define stocktrade 1 "strong increase" 2 "increase" 3 "some increase" ///
							5 "some decrease" ///
							6 "decrease" 7 "strong decrease" 4 "no change"

	label values stocktrades_realized stocktrade
	label variable stocktrades_realized "Realized active adjustments to risky share in response to crisis"
	
	gen realized_morestocks=(stocktrades_realized<=3 & stocktrades_realized!=. )
	la var realized_morestocks "indicator =1 if respondent increased stock share in tot fin wealth"
	gen realized_lessstocks=(stocktrades_realized>4  & stocktrades_realized!=. )
	la var realized_lessstocks "indicator =1 if respondent decreased stock share in tot fin wealth"
	gen realized_nochangestocks=(stocktrades_realized==4 & stocktrades_realized!=. )
	la var realized_nochangestocks "indicator =1 if respondent did not alter stock share in tot fin wealth"
		
	order realized_morestocks realized_lessstocks realized_nochangestocks, after(stocktrades_realized)
	
	foreach var of varlist realized_morestocks -realized_nochangestocks{
	replace `var'=. if stocktrades_realized==.
	}
	*
	
	tab stocktrades_realized
	sum realized_morestocks -realized_nochangestocks
	

	*~ generate 3-outcome measure (increase/no change/decrease) to have it in same format with other outcomes 
	
	gen stocktrades_realized3=.
	replace stocktrades_realized3=1 if stocktrades_realized==1|stocktrades_realized==2|stocktrades_realized==3
	replace stocktrades_realized3=2 if stocktrades_realized==4
	replace stocktrades_realized3=3 if stocktrades_realized==5|stocktrades_realized==6 |stocktrades_realized==7
	label values stocktrades_realized3 change3
	order stocktrades_realized3, after(stocktrades_realized)
	
* planned investment decisions 

	/* Over the next weeks, do you expect your household to make active
		adjustments to the share of stocks and stock mutual funds in total financial
	wealth (both inside and outside of retirement accounts)?

	I expect my household to actively, through purchases and sales of stocks or stock mutual funds,ō

		Šstrongly increase the share of stocks/stock mutual funds in financial wealth.
		Šincrease the share of stocks/stock mutual funds in financial wealth.
		Šsomewhat increase the share of stocks/stock mutual funds in financial wealth.
		Šsomewhat decrease the share of stocks/stock mutual funds in financial wealth.
		Šdecrease the share of stocks/stock mutual funds in financial wealth.
		Šstrongly decrease the share of stocks/stock mutual funds in financial wealth.
		do not expect my household to make any active adjustments to the share of stocks/stock mutual funds in financial wealth.
	
	*/
	
	rename tradeplanned stocktrades_planned
	label values stocktrades_planned stocktrade
	label variable stocktrades_planned "Planned active adjustments to risky share in response to crisis"
	
	tab stocktrades_planned
	
	gen planned_morestocks=(stocktrades_planned<=3 & stocktrades_planned!=. )
	la var planned_morestocks "indicator =1 if respondent plams to increase stock share in tot fin wealth"
	gen planned_lessstocks=(stocktrades_planned>4  & stocktrades_planned!=. )
	la var planned_lessstocks "indicator =1 if respondent plans to decrease stock share in tot fin wealth"
	gen planned_nochangestocks=(stocktrades_planned==4 & stocktrades_planned!=. )
	la var planned_nochangestocks "indicator =1 if respondent plans not alter stock share in tot fin wealth"
	
	foreach var of varlist planned_morestocks- planned_nochangestocks{
	replace `var'=. if stocktrades_planned==.
	}
	*
	
	order planned_morestocks- planned_nochangestocks, after(stocktrades_planned)
	tab stocktrades_planned
	sum planned_morestocks planned_lessstocks planned_nochangestocks
	
	
	*~ generate 3-outcome measure (increase/no change/decrease) to have it in same format with other outcomes 
	
	gen stocktrades_planned3=.
	replace stocktrades_planned3=1 if stocktrades_planned==1|stocktrades_planned==2|stocktrades_planned==3
	replace stocktrades_planned3=2 if stocktrades_planned==4
	replace stocktrades_planned3=3 if stocktrades_planned==5|stocktrades_planned==6 |stocktrades_planned==7
	label values stocktrades_planned3 change3
	order stocktrades_planned3, after(planned_nochangestocks)
	/*
	foreach var of varlist realized_morestocks realized_lessstocks planned_morestocks planned_lessstocks {
		
		replace `var'=100*`var'
		}
		*
		*/
		
******
******	

** 9) ADDITIONAL BACKGROUND
********************************************

	** JOB LOSS

	/*Did you lose your job since the beginning of 2020 as a result of the current
	crisis?*/
		
		rename joblossq1 jobloss_20q1
		tab jobloss_20q1, miss
		replace jobloss_20q1=0 if jobloss_20q1==2 & jobloss_20q1!=.
		label values jobloss_20q1 yesno
		label variable jobloss_20q1 "indicator=1 if respondent lost job over Q1 2020"


	


	** CREDIT CONSTRAINTS 

	/*How difficult would it currently be for your household to obtain a loan of $1,000,
	e.g. by taking out consumer credit or using a credit card or line of credit?
			Very difficult
			Somewhat difficult
			Neither easy nor difficult
			Somewhat easy
			Very easy
			*/
		
		label define constraint 1 "very difficult" 2 "somewhat difficult" 3 "neither easy nor difficult" ///
								4 "somewhat easy" 5 "very easy"
		label values creditconstr constraint
		label variable creditconstr "difficulty of obtaining a $1,000 loan"

	** LOSSES IN PREVIOUS CRISES

	/*	Did you lose wealth that was invested in the stock market due to the Financial Crisis that began in 2007?
		Did you lose wealth that was invested in the stock market due to the burst of the Dot-com Bubble in 2000?
		Did you lose wealth that was invested in the stock market due to the stock market crash of the "Black Monday" in 1987?
		*/ 

		label define crisisloss 1 "experienced no losses" 2 "experienced some losses" 3 "experienced substantial losses"
		foreach var of varlist fincrisis_loss dotcom_loss blackmonday_loss{
		label values `var' crisisloss
		}
		*
		
		label variable fincrisis_loss "indicates whether hh suffered no/some/substantial losses in 2007-2009 fin crisis"
		label variable dotcom_loss "indicates whether hh suffered no/some/substantial losses in dot-com bubble"
		label variable blackmonday_loss "indicates whether hh suffered no/some/substantial losses after Black Monday"

		gen loss_fincris = (fincrisis_loss!=1)
		la var loss_fincris "indicator =1 if hh suffered some or substantial losses in 2007-2009 fin crisis"
		gen loss_dotcom = (dotcom_loss!=1)
		la var loss_dotcom "indicator =1 if hh suffered some or substantial losses in dot-com crisis"
		gen loss_black  = (blackmonday_loss!=1)
		la var loss_black "indicator =1 if hh suffered some or substantial losses after Black Monday"

		gen bigloss_fincris = (fincrisis_loss==3)
		la var bigloss_fincris "indicator =1 if hh suffered substantial losses in 2007-2009 fin crisis"
		gen bigloss_dotcom = (dotcom_loss==3)
		la var bigloss_dotcom "indicator =1 if hh suffered substantial losses in dot-com crisis"
		gen bigloss_black  = (blackmonday_loss==3)
		la var bigloss_black "indicator =1 if hh suffered substantial losses after Black Monday"
		order loss_fincris-bigloss_black, after(blackmonday_loss)


	** FINANCIAL LITERACY 
		rename  fin_knowledge_1  finknowledge
		label variable finknowledge "self-assessed knowledge on personal finances, 0-10"
		
	** STOCK MARKET EXPERIENCE 
	label define experience /// 
	1 "1 to 2 years" 2	"3 to 5 years" ///
	3 "5 to 10 years" 4 "11 to 15 years" ///
	5 "16 to 20 years" 6 "more than 20 years" 

	label values stockexperience experience
	label variable stockexperience "years of stock market experience (brackets)"
	replace stockexperience=. if stockinvestor==0
	
	tab stockexperience
	gen h_stockexperience=(stockexperience>3)
	replace h_stockexperience=. if stockexperience==.
	replace h_stockexperience=. if stockinvestor==. |stockinvestor==0
	order h_stockexperience, after(stockexperience)

	** RISK TOLERANCE 
		rename risk_tolerance_1 risktolerance
		label variable risktolerance "respondent general fin. risk tolerance, 0-10"
		
	** HH FINANCIAL DECISION MAKER 
		rename hhdecision_1 decisionmaker
		replace decisionmaker=decisionmaker-1
		label variable decisionmaker "degree to which respondent decides on hh financial matters herself"
		label define decisionmaker 1 "Someone else decides" 2 "2" 3 "Shared decision-making"  4 "4" 5 "I decide"
		label values decisionmaker decisionmaker

		
	** GEN CONTROLS (risk-tolerance, financial knowledge, decisionmaker) 
	
		sum decisionmaker finknowledge risktolerance
		foreach var of varlist decisionmaker finknowledge risktolerance {
		sum `var',d
		gen h_`var'=(`var'>r(p50))
		replace h_`var'=. if `var'==.
		}
		*
		sum h_decisionmaker h_finknowledge h_risktolerance

				
		

		
	
** 10) ADDITIONAL LABOR BACKGROUND
********************************************
	
	/*What was your personal monthly labor income before taxes (in dollars) in
		January 2020, i.e. before the start of the current crisis? The personal
		monthly labor income refers to your personal monthly wage income from all your
		jobs as well as any income from self-employment.*/
		
		
		rename laborincome laborinc_Jan20
		label variable laborinc_Jan20 "respondent monthly labor income before taxes (in dollars) in	January 2020"
		replace laborinc_Jan20=laborinc_Jan20-19
		
		label define laborinc ///
		1 "Less than $500" 2 "Between $500 and $1000" 3 "Between $1000 and $1500" ///
		4 "Between $1500 and $2000" 5 "Between $2000 and $2500" 6 "Between $2500 and $3000" ///
		7 "Between $3000 and $4000" 8 "Between $4000 and $5000" 9 "Between $5000 and $6000" ///
		10 "Between $6000 and $8000" 11 "Between $8000 and $10000" 12 "Between $10000 and $12000" ///
		13 "Between $12000 and $15000" 14 "Between $15000 and $20000" 15 "More than $20000" 
	
		label values laborinc_Jan20 laborinc
		
		
	/*Which industry/sector did you work in in January 2020, i.e. before the start of the current crisis?*/
	
	/*In January 2020, were you the main contributor of income in your household?*/
	
	label define mainearner 1 "Yes" 2 "No" 3 "My spouse and I contributed equally." 4 "Other"
	label values mainearner mainearner 
	label variable mainearner "main contributor of income to household"
	rename mainearner_4_text mainearner_io
	label variable mainearner_io "main earner: text entry if OTHER is selected"

	gen mainearner_alone=mainearner==1 if mainearner!=.



	
** 12) ADDITIONAL DEMOGRAPHICS
********************************************

** HH SIZE 

	/*Please tell us how many people usually live in your current primary residence,
	including yourself, and excluding non-relatives like roommates or renters?*/
	
	label define hhsize 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6" 7 "7" 8 "8" 9 "9" 10 "10 or more"
	label values hhsize hhsize

		gen famsize_1=(hhsize<=1) if hhsize!=.
		la var famsize_1 "Family members: 1"
		gen famsize_2=(hhsize==2) if hhsize!=.
		la var famsize_2 "Family members: 2"
		gen famsize_3=(hhsize==3) if hhsize!=.
		la var famsize_3 "Family members: 3"
		gen famsize_4=(hhsize==4) if hhsize!=.
		la var famsize_4 "Family members: 4"
		gen famsize_5=(hhsize>=5) if hhsize!=.
		la var famsize_5 "Family members: 5 or more"

		gen famsize_check=famsize_1+famsize_2+famsize_3+famsize_4+famsize_5
		tab famsize_check, m
		drop famsize_check

		rename hhsize famsize
		la var famsize "Familiy size"
		order famsize_1 -famsize_5, after(famsize)

** ZIPCODE 
		
		la var zipcode "respondent residence zipcode"
		
** MARITAL STATUS 
	
		label define marital 1 "Single" 2 "Married" 3 "Divorced" 4 "Widowed" 5 "Separated"
		label values marital marital
		label variable marital "respondent marital status"
		
		
		gen single=(marital==1) if marital!=.
		la var single "Single"
		gen married=(marital==2) if marital!=.
		la var married "Married"
		gen separated=(marital==5) if marital!=.
		la var separated "Separated"
		gen divorced=(marital==3) if marital!=.
		la var divorced "Divorced"
		gen widowed=(marital==4) if marital!=.
		la var widowed "Widowed"


		gen marstat_check=single+married+separated+divorced+widowed
		tab marstat_check, m
		drop marstat_check
		order single-widowed, after(marital)


	
** PARTISANSHIP 

	rename pol partisanship
	label define pol 1 "Democrat" 2 "Republican" 3 "Other" 4 "Prefer not to say"
	label values partisanship pol
	label variable partisanship "respondent political affiliation"
	
	
		gen republican=(partisanship==2) if partisanship!=.
		la var republican "Republican"
		gen democrat=(partisanship==1) if partisanship!=.
		la var democrat "Democrat"
		gen other_party=(partisanship==3) if partisanship!=.
		la var other_party "Other partisanship"
		gen NR_party=(partisanship==4) if partisanship!=.
		la var NR_party "partisanship: No response"

		gen pol_check=republican+democrat+other_party+NR_party
		tab pol_check, m
		drop pol_check
		order republican-NR_party, after(partisanship)



** YEAR OF BIRTH 
			
	gen birthyear1=2000-birthyear
	tab birthyear1
	*br birthyear birthyear1
	*sort birthyear
	order birthyear1, after(birthyear)
	drop birthyear
	rename birthyear1 birthyear
	*tab birthyear
	label var birthyear "respondent year of birth"

	gen age=2020-birthyear
	la var age "Age"

	gen agesq=age^2
	la var agesq "Age squared"
	order age agesq, after(birthyear)
	
** OTHER 
	
	gen some_college_associate_degree=some_college+associate_degree
	gen separated_divorced=separated+divorced
	gen constrained=6-creditconstr
	

	
** 13) DEBRIEF
********************************************

	replace google=0 if google==2
	label values google yesno 
	label variable google "indicator=1 if respondent looked up information during the survey"
	
	rename google_waht google_what
	label variable google_what "specifies what respondent looked up information during the survey"

	label variable purpose "assumed purpose of the survey"
	
	
	rename q103 comments 
	label variable comments "additional comments"
	drop psid pid
	

	
** 14) CLEAN
********************************************

/* set labor-supply related outcome variables
 to missing for the retired and those outside the labor force */ 
 
 foreach var of varlist expec_retireage expec_retirlater expec_retirearly expec_retireage3 ///
 expec_desiredhours expec_morehrs expec_lesshrs expec_desiredhours3 {
 
 replace `var'=. if retired==1 | unempl==1 | empl_other==1 | empl_home==1 
 
 }
 *

 * remove respondents from outside the US 
tab region, miss
drop if region==.

* remove duplicates (rid)
capture drop n
bysort rid: gen n=_n
keep if n==1
drop n 

 
* remove lowest percentile in terms of time spent on the survey
count
sum svytime_min, d

drop if svytime_min<r(p1) | svytime_min>r(p99)
count

tab treatment, miss
drop if treatment==.
drop finished


* drop if financial wealth incompletely reported 
drop if finwealth_NR==1 
count // 7,447



**15 ) TRIM, WINSOR, Z-SCORE
********************************************

foreach var in manip1 manip2 manip3 finprospect stocktrades_planned{
summ `var', d
gen z_`var'=(`var'-r(mean))/r(sd)
}
*


gen manip_index=(z_manip1+z_manip2-z_manip3)/3
summ manip_index, d
gen z_manip_index=(manip_index-r(mean))/r(sd)


foreach var in constrained decisionmaker{
summ `var'
gen z_`var'=((`var'-r(mean))/r(sd))
}
*

*** WEALTH AND INCOME LOSSES 
sum del_retir_perc del_ofin_perc delretir_USD delofin_USD delfinwealth_USD del_finwealth_perc ///
del_hhnetinc_perc delhhnetinc_USD

sum del_finwealth_perc del_retir_perc  del_ofin_perc

** losses to retirement wealth 

winsor2	del_retir_perc, cuts(2 98) trim suffix(_tr02)	

winsor2	del_retir_perc, cuts(2 98)  suffix(_w02)
order del_retir_perc_tr02 del_retir_perc_w02 , after(del_retir_perc)

gen delretir_USD_tr02=(del_retir_perc_tr02/100)*retirewealth_lvl 
*replace delretir_USD_tr02=. if del_retir_perc_tr02==. | retirewealth_lvl==. | retirewealth_lvl==0
order delretir_USD delretir_USD_tr02, after(del_retir_perc_tr02)

sum delretir_USD delretir_USD_tr02, d

/*gen del_retir_oftot_tr02=share_retir_finwealth*del_retir_perc_tr02
replace del_retir_oftot_tr02=. if del_retir_perc_tr02==. | retirewealth_lvl==. | retirewealth_lvl==0
order del_retir_oftot del_retir_oftot_tr02, after(del_retir_perc_tr02)
*/ 


** losses to other financial wealth 
winsor2	del_ofin_perc, cuts(2 98) trim suffix(_tr02)
winsor2	del_ofin_perc, cuts(2 98)  suffix(_w02)
order del_ofin_perc_w02 del_ofin_perc_tr02, after(del_ofin_perc)

gen delofin_USD_tr02=(del_ofin_perc_tr02/100)*ofinwealth_lvl 
*replace delofin_USD_tr02=. if del_ofin_perc_tr02==. | ofinwealth_lvl==. | ofinwealth_lvl==0
order delofin_USD delofin_USD_tr02, after(del_ofin_perc_tr02)
sum delofin_USD delofin_USD_tr02, d
					
/*gen del_ofin_oftot_tr02=share_ofin_finwealth*del_ofin_perc_tr02
replace del_ofin_oftot_tr02=. if del_ofin_perc_tr02==. | ofinwealth_lvl==. | ofinwealth_lvl==0
order del_ofin_oftot del_ofin_oftot_tr02, after(del_ofin_perc_tr02)
*/				
				
** losses to total financial wealth  winsorize 
winsor2 del_finwealth_perc, cuts(2 98) trim	suffix(_tr02)
winsor2 del_finwealth_perc, cuts(2 98) 	suffix(_w02)
order del_finwealth_perc del_finwealth_perc_w02 del_finwealth_perc_tr02, after(gainofin_perc)		

winsor2	delfinwealth_USD, cuts(2 98) trim suffix(_tr02)	
winsor2	delfinwealth_USD, cuts(2 98)  suffix(_w02)	

			
** losses to hh net income 
winsor2 del_hhnetinc_perc, cuts(2 98) trim	suffix(_tr02)
winsor2 del_hhnetinc_perc, cuts(2 98) suffix(_w02)
order del_hhnetinc_perc del_hhnetinc_perc_w02 del_hhnetinc_perc_tr02, before(incdiff_20q1)
						
gen delhhnetinc_USD_tr02 = (del_hhnetinc_perc_tr02/100)*hhnetinc_2019
	
order delhhnetinc_USD delhhnetinc_USD_tr02, after(del_hhnetinc_perc_tr02)
							
		*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
		** LOSS BINS  WITH TRIMMED VARIABLES
		*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

				* make delta-group variables such that 5 = highest loss, 1 = highest gain
					sum del_finwealth_perc_tr02, d
					gen del_finwealth_percNeg_tr02 = -del_finwealth_perc_tr02
					
					sum del_ofin_perc_tr02, d
					gen del_ofin_percNeg_tr02 = -del_ofin_perc_tr02
					sum del_retir_perc_tr02, d
					gen del_retir_percNeg_tr02 = -del_retir_perc_tr02
					sum del_hhnetinc_perc_tr02, d
					gen del_hhnetinc_percNeg_tr02 = -del_hhnetinc_perc_tr02
					
				* make groups for variables with lots of bunching:
					foreach x in del_ofin del_retir  del_finwealth  del_hhnetinc {
						sort `x'_perc_tr02
						gen `x'_tr02_alt = int(5*(_n-1)/_N)+1 if `x'_perc!=.
						xtile `x'_tr02_grp = `x'_perc, nq(5)
					}
				* make groups for variables with lots of bunching:
					foreach x in del_finwealth_percNeg_tr02 del_hhnetinc_percNeg_tr02 del_ofin_percNeg_tr02 del_retir_percNeg_tr02 {
						sort `x'
						gen `x'_alt = int(5*(_n-1)/_N)+1 if `x'!=.
						xtile `x'_grp = `x', nq(5)
					}		
					
			
				tab del_finwealth_percNeg_tr02_grp
				tab del_finwealth_percNeg_tr02_alt
				tab del_hhnetinc_percNeg_tr02_alt
				tab del_hhnetinc_percNeg_tr02_grp
				
				tab del_ofin_percNeg_tr02_alt 
				tab del_ofin_percNeg_tr02_grp 
				tab del_retir_percNeg_tr02_alt 
				tab del_retir_percNeg_tr02_grp
							
				*replace del_finwealth_percNeg_grp = del_finwealth_percNeg_alt
				replace del_hhnetinc_percNeg_grp = del_hhnetinc_percNeg_alt
				replace del_ofin_percNeg_grp = del_ofin_percNeg_alt
				*replace del_retir_percNeg_grp = del_retir_percNeg_alt


				
	** recovery elief variables 
	
	sum recovery_duration, d
	winsor2 recovery_duration, cuts(0 99) replace
		
	
	sum recov_hhwealth_duration, d
	winsor2 recov_hhwealth_duration, cuts(0 99) replace
	sum recov_hhwealth_duration, d
	local max = r(max)
	*replace recov_hhwealth_duration = `max' if manip_ownwealth==9999
	sum recov_hhwealth_duration, d

	replace recov_hhwealth_duration=0 if finwealth_Jan20==0
	replace recov_hhwealth_duration=0 if del_finwealth_perc>=0
	
	gen never_ownwealth = (manip_ownwealth==9999)
	tab never_ownwealth
	
		sum recov_owninc_duration, d
	winsor2 recov_owninc_duration, cuts(1 99) replace
	sum recov_owninc_duration, d
	local max = r(max)
	*replace recov_owninc_duration = `max' if manip_owninc==9999
	sum recov_owninc_duration, d

	gen never_owninc = (manip_owninc==9999)
	tab never_owninc


	replace recov_owninc_duration=0 if hhinc_lvl==0
	replace recov_owninc_duration=0 if del_hhnetinc_perc>=0

	
	
			winsor2 del_spend20_perc, cuts(1 99) trim
			rename del_spend20_perc_tr del_spend20_perc_tr01
			winsor2 del_spend20_perc, cuts(2 98) trim
			rename del_spend20_perc_tr del_spend20_perc_tr02
			winsor2 del_spend20_perc, cuts(2 98) suffix(_w02)
			order del_spend20_perc del_spend20_perc_w02 del_spend20_perc_tr01 del_spend20_perc_tr02, after(expec_spend3)
			
				
	sum del_hhnetinc_exp20, d
	winsor2 del_hhnetinc_exp20, cuts(2 98) suffix(_tr02)
	sum del_hhnetinc_exp20_tr02, d
	
	
	


** 16) PREPARE ADDITIONAL VARIABLES FOR ANALYSIS
*****************************************************

replace recovery_duration=13 if recovery_duration>=13

gen riskshare_finwealth_Jan201=riskshare_finwealth_Jan20
replace riskshare_finwealth_Jan201=0 if finwealth_Jan20==0


gen stockowner=riskshare_finwealth_Jan201>0 if riskshare_finwealth_Jan201!=.

replace empl_other=1 if student==1 |empl_home==1
	
foreach var of varlist /*retirewealth_lvl ofinwealth_lvl*/ realestate_lvl debt_lvl{
replace `var'=0 if `var'==. 
gen ln_`var'=ln(`var'+1)
}
foreach var of varlist retirewealth_lvl ofinwealth_lvl /*realestate_lvl debt_lvl*/{
replace `var'=0 if `var'==. 
gen ln_`var'=ln(`var'+1)
}
*
replace stockexperience=0 if stockinvestor==0
*replace h_stockexperience=0 if stockinvestor==0
replace del_finwealth_perc=0 if del_finwealth_perc==.

*replace finwealth_Jan20=0 if finwealth_Jan20==.
gen ln_finwealth_Jan20=ln(finwealth_Jan20+1)

replace share_retir_finwealth=100*share_retir_finwealth
/** express all outcome variables in percentage points 	
	
		foreach var of 	varlist ///
					expec_debthigher  ///
					expec_morehrs  ///
					expec_retirlater   {
					
					replace `var'=100*`var'
		}
		*
*/

				/* also for timmed variables	
				replace del_finwealth_perc_tr02 = . if finwealth_Jan20==.
				replace delretir_USD_tr02 = . if retirwealth_Jan20==16
				replace delofin_USD_tr02 = . if ofinwealth_Jan20==16
				
				replace del_finwealth_perc_tr02 = 0 if finwealth_Jan20==0
				replace del_ofin_perc_tr02 = 0 if ofinwealth_Jan20==1
				replace del_retir_perc_tr02 = 0 if retirwealth_Jan20==1
				replace delofin_USD_tr02 = 0 if ofinwealth_Jan20==1
				replace delretir_USD_tr02 = 0 if retirwealth_Jan20==1
				
				replace del_ofin_perc_tr02=. if del_finwealth_perc_tr02==.
				replace del_retir_perc_tr02=.  if del_finwealth_perc_tr02==.
				
				replace delofin_USD_tr02=. if delfinwealth_USD_tr02==.
				replace delretir_USD_tr02=.  if delfinwealth_USD_tr02==.
				
				
				sum del_ofin_perc_tr02 del_retir_perc_tr02 del_finwealth_perc_tr02 	
				*/
	
	
	tab stocktrades_realized, gen(trades_realized) 
	tab stocktrades_planned, gen(trades_planned)
	
	gen realized_mmstocks=(trades_realized1==1 |trades_realized2==1)
	gen realized_mlstocks=(trades_realized6==1 |trades_realized7==1)
	gen realized_normore=(stocktrades_realized>3)
	
	gen trade_realized=(stocktrades_realized!=4)
	gen realized_anychangestocks =1-realized_nochangestocks

	** set experienced losses =0 if respondents have not been 18 by that time 
	tab blackmonday_loss, miss
	replace blackmonday_loss=1 if age< 49
	replace loss_black=0 if age < 49
	replace bigloss_black=0 if age< 49
	
	tab dotcom_loss, miss
	replace dotcom_loss=1 if age < 35
	replace loss_dotcom=0 if age < 35
	replace bigloss_dotcom=0 if age< 35
	
	tab fincrisis_loss, miss
	replace fincrisis_loss=1 if age < 28
	replace loss_fincris=0 if age < 28
	replace bigloss_fincris=0 if age< 28
	
	
	* generate crisis inicators

	gen fincrisis= .
	replace fincrisis = fincrisis_loss-1
	replace fincrisis = 1 if fincrisis==2
	gen dotcom= .
	replace dotcom = dotcom_loss-1
	replace dotcom = 1 if dotcom==2
	gen bm= .
	replace bm = blackmonday_loss-1
	replace bm = 1 if bm==2

	gen fincrisis_big= .
	replace fincrisis_big = 0 if fincrisis!=.
	replace fincrisis_big = 1 if fincrisis_loss==3
	gen dotcom_big= .
	replace dotcom_big =  0 if dotcom!=.
	replace dotcom_big = 1 if dotcom_loss==3
	gen bm_big= .
	replace bm_big = 0 if bm!=.
	replace bm_big = 1 if blackmonday_loss==3
	
	
	gen planned_anychangestocks=1-planned_nochangestocks
	
	
	
** 16) EXPERIMENTAL MEASURES 
********************************************

gen treated=tr_fincrisis+tr_dotcom+tr_black
replace treated=. if control_pure==1	


replace stocktrades_planned=8-stocktrades_planned
gen exp_ret_mean= ///
(retdist_neg30/100)*(-40)+ ///
(retdist_neg30_15/100)*(-22.5)+ ///
(retdist_neg15_5/100)*(-10)+ ///
(retdist_neg5_0/100)*(-2.5)+ ///
(retdist_pos0_5/100)*(2.5)+ ///
(retdist_pos5_15/100)*(10)+ ///
(retdist_pos15_30/100)*(22.5)+ ///
(retdist_pos30/100)*(40)
gen exp_ret_var= ///
(retdist_neg30/100)*(-40)^2+ ///
(retdist_neg30_15/100)*(-22.5)^2+ ///
(retdist_neg15_5/100)*(-10)^2+ ///
(retdist_neg5_0/100)*(-2.5)^2+ ///
(retdist_pos0_5/100)*(2.5)^2+ ///
(retdist_pos5_15/100)*(10)^2+ ///
(retdist_pos15_30/100)*(22.5)^2+ ///
(retdist_pos30/100)*(40)^2 - exp_ret_mean^2
gen exp_ret_sd=sqrt(exp_ret_var)
gen exp_delinc2020=0 if netincdiff20_same==1
replace exp_delinc2020=-netinclower20_perc if netincdiff20_lower==1
replace exp_delinc2020=netinchigher20_perc if netincdiff20_higher==1
winsor exp_delinc2020, gen(exp_delinc2020_w01) p(0.01)
gen exp_delinc2020_t01=exp_delinc2020 if exp_delinc2020==exp_delinc2020_w01
winsor exp_delinc2020, gen(exp_delinc2020_w02) p(0.02)
gen exp_delinc2020_t02=exp_delinc2020 if exp_delinc2020==exp_delinc2020_w02



gen info=.
replace info=5.5 if tr_fincrisis==1|control_fincrisis==1
replace info=7 if tr_dotcom==1|control_dotcom==1
replace info=2 if tr_black==1|control_black==1

gen percgap=info-prior

gen arm_fincrisis=tr_fincrisis+control_fincrisis
gen arm_dotcom=tr_dotcom+control_dotcom
gen arm_black=tr_black+control_black


** 17) MERGE IMPUTED CONSUMPTION FROM CEX 
********************************************

merge n:1 hh_income famsize using "data/other/totexp_inc_famsize.dta"
drop if _merge==2
drop _merge

replace tot_exp=tot_exp*(1+(1.81175/100))
sum tot_exp, d

gen del_spend20_usd		= (del_spend20_perc/100)*tot_exp
gen del_spend20_usd_w02	= (del_spend20_perc_w02/100)*tot_exp 
gen del_spend20_usd_tr02= (del_spend20_perc_tr02/100)*tot_exp


winsor2 del_spend20_usd, cuts(2 98) trim suffix (_tr02alt)
winsor2 delretir_USD , cuts(2 98) trim suffix (_tr02alt)
winsor2 delofin_USD , cuts(2 98) trim suffix (_tr02alt)
winsor2  delfinwealth_USD , cuts(2 98) trim suffix (_tr02alt)



winsor2 delhhnetinc_USD, cuts(2 98) trim suffix (_tr02alt)
gen delhhnetinc_exp20_USD=(del_hhnetinc_exp20/100)*hhnetinc_19_midpt
winsor2 delhhnetinc_exp20_USD, cuts(2 98) trim suffix (_tr02alt)
sum delhhnetinc_exp20_USD_tr02alt, d

sum  delretir_USD delofin_USD delfinwealth_USD
sum del_spend20_usd_tr02alt delretir_USD_tr02alt delofin_USD_tr02alt delhhnetinc_USD_tr02alt ///
 delhhnetinc_exp20_USD_tr02alt delfinwealth_USD_tr02alt
 
 
gen delhhnetinc_USD_tr02_qtr = delhhnetinc_USD_tr02/4
gen delhhnetinc_USD_tr02alt_qtr = delhhnetinc_USD_tr02alt/4


** 18) SAVE DATA
********************************************

compress
save "data/processed/data_1.dta", replace

exit




*****
*****
*****













